Repository navigation
Method name lookup - #1844
Closed
skatkov wants to merge 6 commits into
Closed
Method name lookup#1844skatkov wants to merge 6 commits into
skatkov wants to merge 6 commits into
Conversation
Keep name buckets private behind scalar lookups with optional predicates. Preserve scan behavior for mutable name strings and use validity tokens for explicitly renamed methods. Discard derived cache state when copying or marshaling the collection, with focused coverage for lookup boundaries, mutable names, and direct serialization.
Store methods in MethodList and route all four name lookup paths through its scalar lookup API while preserving ordering and singleton matching. Cover additions, renames, filtering, shared collections, and mutations, together with class promotion, store loading, merging, and live-preview replacement and removal.
Documentation previewCommit: |
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.
This PR speeds up method-name lookups in RDoc and makes the method collection read-only so callers cannot accidentally invalidate the lookup cache.
What changed
Previously, each lookup scanned the whole method list. Now,
lib/rdoc/code_object/context/method_list.rbmaintains a lazy index mapping each name to its matching methods.name=.The index keeps methods in list order. Class/instance filtering happens at lookup time, preserving the existing selection behavior. Attributes remain outside this index.
flowchart TD Lookup["Context method lookup"] --> List["Internal MethodList"] List --> Names{"All names frozen?"} Names -->|Yes| Index["Lazy name index<br/>Index appended entries only"] Names -->|No| Scan["Scan current method names"] Index --> Candidates["Matching methods in list order"] Scan --> Candidates Candidates --> Result["Return first match<br/>Apply class/instance filter if requested"] Add["add_method"] -.->|Extend on next lookup| Index Change["Removal, replacement,<br/>or method rename"] -.->|Invalidate| Index Reader["context.method_list"] --> Snapshot["Frozen Array snapshot<br/>Method objects remain mutable"] List -.->|Copy contents| SnapshotPublic API change
Context#method_listnow returns a frozen Array snapshot, rather than exposing the mutable backing collection.Callers change membership through:
Existing writers in Store loading, live-preview cleanup, visibility filtering, and class promotion/merging were migrated to these operations.
replace_methodschanges the documentation list only; it deliberately leavesmethods_hashregistrations unchanged.This is a breaking change for callers that directly mutate
method_list. Method objects themselves are not frozen, so renaming remains supported.Parser to return frozen method names.
Ruby, C and RBS parser to forcefully return frozen strings for method names. This greatly improves speed improvements.
-> TODO: Add more information about this
Other generators
I have tested this branch with other generators - rdoc-markdown, sdoc and hanna. All seem to be working just fine with these breaking changes with no modifications required.
Open Questions