pathname: build eager-init type objects once, not per allocation#23267
Merged
MikeMcQuaid merged 2 commits intoJul 22, 2026
Conversation
MikeMcQuaid
reviewed
Jul 22, 2026
MikeMcQuaid
left a comment
Member
There was a problem hiding this comment.
Nice cleanup! Interested in @dduugg's thoughts here before we merge.
Also: one test is 🔴
hyuraku
force-pushed
the
pathname-eager-init-type-alias
branch
from
July 22, 2026 13:16
90386c3 to
c7f5bb0
Compare
dduugg
approved these changes
Jul 22, 2026
dduugg
left a comment
Member
There was a problem hiding this comment.
Much safer than my approach, ty! It's a nice, resuable technique that we can use in other hotspots as well.
MikeMcQuaid
approved these changes
Jul 22, 2026
Member
|
Thanks again @hyuraku! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By default, runtime type checking is off. In that mode,
standalone/sorbet.rbreplaces
T.letwith a version that ignores the type argument. But Ruby stillevaluates that argument first. So
T.let(nil, T.nilable(String))builds a typeobject and then throws it away.
EagerInitializeExtension#initializeruns everytime a
Pathnameis created, and it does this six times. #23078 found this wasone of the biggest remaining CPU costs in
brew upgrade --dry-runandbrew outdated.This change moves the three types into
T.type_aliasconstants. They are builtonce, and
#initializejust uses the constants. The types themselves do notchange, so Sorbet still sees
@magic_numberasT.nilable(String)and so on.This change does not touch sorbet-runtime itself. #23078 tried to make
T.nilable,T::Array[]and friends share instances globally, but that brokehow
T::Propsreads optionality and was reverted in #23091. Moving only theseconstants avoids that problem.
Behaviour is the same:
brew outdatedandbrew info --installed --json=v2print byte-identical output before and after. With the runtime disabled,
Hyperfine shows a consistent speedup (three alternating rounds of 20 runs,
3 warmup,
mainvs this branch):brew outdatedbrew info --installed --json=v2The ratio was stable across all three rounds (1.08–1.09 and 1.07–1.08). Commands
that create fewer Pathnames show no measurable change. A stackprof profile of
brew outdatedshows the union-type construction dropping from 36 samples to 9.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?AI (Claude Code) found the cost by profiling
brew outdated, wrote the change,and ran the benchmarks. I reviewed the change and ran
brew lgtmlocally.