Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Avoid caching atomic type specializations#25663

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/reduce-retained-type-memory
Jun 5, 2026
Merged

[ty] Avoid caching atomic type specializations#25663
charliermarsh merged 1 commit into
mainfrom
charlie/reduce-retained-type-memory

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

apply_specialization currently creates and retains a Salsa query for every input type, including atomic types whose specialization always returns the original type.

This change handles those specialization-invariant variants before entering the tracked query. Types that can contain type variables continue through the existing tracked implementation, preserving specialization and cycle behavior.

On a large codebase, this reduced retained memory by 1.06% without a measurable runtime regression.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Jun 5, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 92.13%. The percentage of expected errors that received a diagnostic held steady at 87.18%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 38.64MB 38.49MB -0.39% (153.88kB) ⬇️
trio 98.96MB 98.47MB -0.49% (500.33kB) ⬇️
sphinx 237.91MB 236.38MB -0.64% (1.53MB) ⬇️
prefect 653.76MB 649.45MB -0.66% (4.30MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
Type<'db>::apply_specialization_::interned_arguments 222.27kB 0.00B -100.00% (222.27kB) ⬇️
Type<'db>::apply_specialization_ 217.73kB 0.00B -100.00% (217.73kB) ⬇️
Type<'db>::apply_specialization_inner_ 0.00B 181.75kB +181.75kB (new) ⬇️
Type<'db>::apply_specialization_inner_::interned_arguments 0.00B 170.86kB +170.86kB (new) ⬇️
infer_deferred_types 499.45kB 475.92kB -4.71% (23.53kB) ⬇️
infer_expression_types_impl 1.03MB 1.01MB -1.53% (16.15kB) ⬇️
infer_definition_types 1.62MB 1.61MB -0.74% (12.38kB) ⬇️
Type<'db>::try_call_dunder_get_ 378.63kB 372.21kB -1.70% (6.42kB) ⬇️
infer_scope_types_impl 844.35kB 839.94kB -0.52% (4.41kB) ⬇️
infer_statement_types_impl 42.56kB 41.13kB -3.36% (1.43kB) ⬇️
StaticClassLiteral<'db>::try_metaclass_ 52.22kB 51.23kB -1.89% (1008.00B) ⬇️
Type<'db>::member_lookup_with_policy_ 541.01kB 540.75kB -0.05% (264.00B) ⬇️
function_known_decorators 151.46kB 151.21kB -0.17% (264.00B) ⬇️
Type<'db>::class_member_with_policy_ 576.76kB 576.52kB -0.04% (240.00B) ⬇️
lookup_dunder_new_inner 18.42kB 18.21kB -1.15% (216.00B) ⬇️
... 7 more

trio

Name Old New Diff Outcome
Type<'db>::apply_specialization_ 648.62kB 0.00B -100.00% (648.62kB) ⬇️
Type<'db>::apply_specialization_::interned_arguments 636.17kB 0.00B -100.00% (636.17kB) ⬇️
Type<'db>::apply_specialization_inner_ 0.00B 557.78kB +557.78kB (new) ⬇️
Type<'db>::apply_specialization_inner_::interned_arguments 0.00B 506.41kB +506.41kB (new) ⬇️
infer_deferred_types 2.05MB 1.96MB -4.35% (91.22kB) ⬇️
infer_expression_types_impl 6.74MB 6.68MB -0.91% (62.72kB) ⬇️
infer_definition_types 6.89MB 6.85MB -0.65% (45.82kB) ⬇️
infer_scope_types_impl 4.08MB 4.06MB -0.68% (28.52kB) ⬇️
Type<'db>::try_call_dunder_get_ 1.31MB 1.29MB -1.73% (23.23kB) ⬇️
infer_expression_type_impl 1.47MB 1.46MB -0.92% (13.78kB) ⬇️
all_negative_narrowing_constraints_for_expression 662.71kB 660.06kB -0.40% (2.65kB) ⬇️
all_narrowing_constraints_for_expression 696.46kB 693.83kB -0.38% (2.62kB) ⬇️
StaticClassLiteral<'db>::try_metaclass_ 160.70kB 158.89kB -1.12% (1.80kB) ⬇️
Type<'db>::member_lookup_with_policy_ 1.88MB 1.88MB -0.09% (1.73kB) ⬇️
Type<'db>::class_member_with_policy_ 1.96MB 1.95MB -0.06% (1.27kB) ⬇️
... 13 more

sphinx

Name Old New Diff Outcome
Type<'db>::apply_specialization_::interned_arguments 1.80MB 0.00B -100.00% (1.80MB) ⬇️
Type<'db>::apply_specialization_ 1.78MB 0.00B -100.00% (1.78MB) ⬇️
Type<'db>::apply_specialization_inner_ 0.00B 1.49MB +1.49MB (new) ⬇️
Type<'db>::apply_specialization_inner_::interned_arguments 0.00B 1.38MB +1.38MB (new) ⬇️
infer_deferred_types 4.67MB 4.41MB -5.49% (262.69kB) ⬇️
infer_expression_types_impl 20.84MB 20.61MB -1.08% (231.21kB) ⬇️
infer_definition_types 21.31MB 21.15MB -0.77% (167.09kB) ⬇️
Type<'db>::try_call_dunder_get_ 5.11MB 5.05MB -1.09% (57.23kB) ⬇️
infer_scope_types_impl 13.21MB 13.15MB -0.39% (53.23kB) ⬇️
infer_expression_type_impl 2.94MB 2.92MB -0.70% (21.03kB) ⬇️
infer_statement_types_impl 489.35kB 470.18kB -3.92% (19.17kB) ⬇️
all_narrowing_constraints_for_expression 2.69MB 2.68MB -0.35% (9.53kB) ⬇️
all_negative_narrowing_constraints_for_expression 2.61MB 2.60MB -0.36% (9.50kB) ⬇️
loop_header_reachability 357.28kB 352.73kB -1.27% (4.55kB) ⬇️
try_call_bin_op_return_type_impl 227.68kB 224.51kB -1.39% (3.16kB) ⬇️
... 31 more

prefect

Name Old New Diff Outcome
Type<'db>::apply_specialization_ 3.72MB 0.00B -100.00% (3.72MB) ⬇️
Type<'db>::apply_specialization_::interned_arguments 3.62MB 0.00B -100.00% (3.62MB) ⬇️
Type<'db>::apply_specialization_inner_ 0.00B 3.10MB +3.10MB (new) ⬇️
Type<'db>::apply_specialization_inner_::interned_arguments 0.00B 2.74MB +2.74MB (new) ⬇️
infer_definition_types 82.05MB 81.22MB -1.01% (845.55kB) ⬇️
infer_expression_types_impl 59.17MB 58.41MB -1.28% (776.21kB) ⬇️
infer_deferred_types 10.27MB 9.71MB -5.47% (575.79kB) ⬇️
infer_scope_types_impl 50.36MB 50.07MB -0.58% (299.30kB) ⬇️
Type<'db>::try_call_dunder_get_ 11.75MB 11.63MB -1.01% (122.13kB) ⬇️
infer_expression_type_impl 8.35MB 8.27MB -0.87% (74.09kB) ⬇️
infer_statement_types_impl 955.46kB 908.10kB -4.96% (47.37kB) ⬇️
all_narrowing_constraints_for_expression 8.44MB 8.42MB -0.34% (29.63kB) ⬇️
all_negative_narrowing_constraints_for_expression 8.26MB 8.23MB -0.34% (28.84kB) ⬇️
Type<'db>::member_lookup_with_policy_ 16.69MB 16.68MB -0.09% (14.95kB) ⬇️
function_known_decorators 4.17MB 4.16MB -0.21% (8.98kB) ⬇️
... 28 more

@astral-sh-bot

astral-sh-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh marked this pull request as ready for review June 5, 2026 16:37
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila June 5, 2026 16:37
@charliermarsh charliermarsh merged commit eb55c29 into main Jun 5, 2026
59 checks passed
@charliermarsh charliermarsh deleted the charlie/reduce-retained-type-memory branch June 5, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants