[ty] Narrow semantic node ID lookup tables#26363
Draft
charliermarsh wants to merge 1 commit into
Draft
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.47%. The percentage of expected errors that received a diagnostic held steady at 89.19%. The number of fully passing files held steady at 95/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownflake8
trio
sphinx
prefect
|
|
cb78a8e to
00a5263
Compare
2233529 to
7215cd9
Compare
MichaReiser
reviewed
Jun 26, 2026
MichaReiser
left a comment
Member
There was a problem hiding this comment.
I'll wait for the conclusion on the base PR before reviewing this PR (the improvements look promising but we may need to move/change the PR depending on the outcome of the base PR)
00a5263 to
5062fa2
Compare
5062fa2 to
e8c35b9
Compare
Store indexed semantic IDs as 16-bit values when every entry fits, with a full-width fallback for unusually large files. Apply the narrow representation to AST use IDs and scope lookups, partitioning primary and type-parameter scopes so distinct scope keys that share a node index remain separate.
e8c35b9 to
42ab9af
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.
Summary
File-local semantic IDs are stored at their full width in several immutable lookup tables, even though almost every file uses fewer than 65,536 IDs.
This adds an independent
NarrowNodeIndexMap. When every value fits, it stores each mapping as a packed six-byte entry containing a 32-bit node index and a 16-bit semantic ID, avoiding the padding of a(NodeKey, u16)tuple. Unusually large files fall back to the existing full-widthFrozenMaprepresentation. This PR does not depend on #26350.We use the narrow representation for AST use IDs and scope lookups. Scope lookups keep module, primary-scope, and type-parameter-scope entries separate because a node can anchor both a primary scope and a type-parameter scope.