Replace the method sorter with a direct DFS - #3142
Merged
Merged
Conversation
`MethodBuilder::Methods#each` sorted the methods of every type with TSort, although the sort exists only to yield the original method of an alias before the alias, and to detect recursive aliases. Without an alias member every method is its own SCC and the sort yields them in insertion order, so check for aliases in one pass and iterate the table directly when there is none. The sort was one of the two hotspots of building the definitions of every type in an environment, next to the variance validation -- 19% of a whole-environment warmup of a large Rails application, whose methods mostly come from generated RBS files without aliases. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
soutaro
enabled auto-merge
September 2, 2026 13:04
`MethodBuilder::Methods#each` sorted the methods with the generic TSort when the type has an alias, paying for the enumerator and block machinery of the library on every method. The graph is trivial -- each method has at most one edge, to the original of an alias -- so a direct DFS yields the same order: originals before their aliases, everything else in insertion order. The recursive alias detection is preserved, including yielding a self-alias as is, which forms a size-1 SCC that the sorter never reported as recursive. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
soutaro
force-pushed
the
method-builder-dfs
branch
from
September 2, 2026 13:07
c2fe23f to
56699e8
Compare
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.
MethodBuilder::Methods#eachsorted the methods topologically withTSortso that the original of an alias is yielded before the alias,building the graph of all the methods on every call, although most
types have no alias at all.
eachnow yields the methods in definition order when there is noalias, and otherwise walks the alias chain of each method with a small
DFS that yields the originals first and raises
RecursiveAliasDefinitionErroron a cycle, as the sorter did. Buildingthe definitions of all 1,806 types of Steep's environment goes from
2.5s to 1.9s.