[ty] Avoid retaining empty use-def tables#26018
Merged
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 94.37%. The percentage of expected errors that received a diagnostic held steady at 89.00%. The number of fully passing files held steady at 94/134. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownflake8
trio
sphinx
prefect
|
|
97c4cc4 to
2c7a220
Compare
2c7a220 to
53c8775
Compare
MichaReiser
approved these changes
Jun 17, 2026
MichaReiser
left a comment
Member
There was a problem hiding this comment.
I recognize more and more Salsa patterns in ty's code ;)
MichaReiser
reviewed
Jun 17, 2026
| narrowing_constraints: NarrowingConstraints, | ||
| /// Constraint lookup tables, absent when all retained constraints are built-in terminal | ||
| /// values that require no table lookup. | ||
| constraint_tables: Option<Box<ConstraintTables<'db>>>, |
Member
There was a problem hiding this comment.
Is it common that UseDefMaps without a constraint_tables have an extra? Or what's the reasoning that this isn't part of extra?
Member
Author
There was a problem hiding this comment.
I think so, because extra is always populated when you have a read given that it contains binding_by_use:
def f(x):
y = x
return y(This is still empty in 65-75% of scopes though.)
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
We retain a
UseDefMapfor every scope. Several of its collection fields are empty in most scopes, but their fixed-size headers still remain in every map and add up across the semantic index.This moves two sets of fields behind optional allocations. Predicate and constraint tables are omitted when no retained reachability or narrowing formula needs a table lookup. Bindings indexed by use, member states, and enclosing-scope snapshots share a second allocation that is omitted when all of those collections are empty.
Scopes without constraint tables use one shared empty value, preserving the existing lookup APIs without propagating optional values through evaluation. Predicates built for those scopes are also discarded because no retained constraint can reference them. The remaining fields share storage only to reduce the size of common
UseDefMapvalues; they do not represent a new semantic abstraction.The diagnostic comparison reports no changes.
Performance
The memory report shows total retained-memory reductions of 0.29–1.43% across Flake8, Trio, Sphinx, and Prefect. Within
semantic_index, retained memory falls by 1.24–5.32%, saving between 491.55kB and 1.51MB.