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

Skip to content

[ty] Avoid caching trivial class-header queries#25692

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/avoid-caching-trivial-class-headers
Jun 6, 2026
Merged

[ty] Avoid caching trivial class-header queries#25692
charliermarsh merged 1 commit into
mainfrom
charlie/avoid-caching-trivial-class-headers

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

StaticClassLiteral currently creates and retains Salsa queries for explicit bases, inherited generic contexts, TypedDict detection, metaclass resolution, inheritance-cycle detection, and code-generator classification even when a class header has no bases or explicit metaclass.

This records whether those syntax forms are present when constructing the class literal and returns the trivial result before entering the tracked query when they are absent. Classes with bases or explicit metaclasses continue through the existing tracked implementations.

On a large codebase, this reduced retained memory from 93.03 GB to 91.54 GB, saving 1.49 GB (1.60%) on top of the decorator and type-parameter fast paths from #25689, without a runtime regression.

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

astral-sh-bot Bot commented Jun 6, 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.16%. The percentage of expected errors that received a diagnostic held steady at 87.31%. The number of fully passing files held steady at 92/134.

@astral-sh-bot

astral-sh-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 37.30MB 37.03MB -0.71% (271.89kB) ⬇️
trio 93.75MB 92.66MB -1.16% (1.09MB) ⬇️
sphinx 221.10MB 218.23MB -1.30% (2.87MB) ⬇️
prefect 605.82MB 595.92MB -1.63% (9.90MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
Type<'db>::class_member_with_policy_ 394.59kB 346.52kB -12.18% (48.07kB) ⬇️
StaticClassLiteral<'db>::try_metaclass_ 47.53kB 0.00B -100.00% (47.53kB) ⬇️
member_lookup_with_policy_inner 500.30kB 467.23kB -6.61% (33.07kB) ⬇️
try_metaclass_inner 0.00B 31.30kB +31.30kB (new) ⬇️
StaticClassLiteral<'db>::explicit_bases_ 29.82kB 0.00B -100.00% (29.82kB) ⬇️
infer_deferred_types 456.35kB 428.04kB -6.20% (28.31kB) ⬇️
infer_expression_types_impl 984.51kB 958.78kB -2.61% (25.73kB) ⬇️
StaticClassLiteral<'db>::is_typed_dict_ 24.80kB 0.00B -100.00% (24.80kB) ⬇️
explicit_bases_inner 0.00B 24.27kB +24.27kB (new) ⬇️
infer_definition_types 1.58MB 1.56MB -1.43% (23.12kB) ⬇️
infer_scope_types_impl 818.46kB 797.04kB -2.62% (21.42kB) ⬇️
is_typed_dict_inner 0.00B 17.95kB +17.95kB (new) ⬇️
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 17.73kB 0.00B -100.00% (17.73kB) ⬇️
StaticClassLiteral<'db>::inheritance_cycle_ 12.34kB 0.00B -100.00% (12.34kB) ⬇️
inherited_legacy_generic_context_inner 0.00B 12.17kB +12.17kB (new) ⬇️
... 29 more

trio

Name Old New Diff Outcome
infer_deferred_types 1.87MB 1.71MB -8.25% (157.61kB) ⬇️
infer_scope_types_impl 3.91MB 3.77MB -3.63% (145.15kB) ⬇️
StaticClassLiteral<'db>::try_metaclass_ 145.03kB 0.00B -100.00% (145.03kB) ⬇️
infer_definition_types 6.63MB 6.50MB -2.07% (140.43kB) ⬇️
infer_expression_types_impl 6.27MB 6.14MB -2.09% (134.52kB) ⬇️
Type<'db>::class_member_with_policy_ 1.39MB 1.25MB -9.43% (133.83kB) ⬇️
try_metaclass_inner 0.00B 100.96kB +100.96kB (new) ⬇️
member_lookup_with_policy_inner 1.74MB 1.65MB -5.48% (97.82kB) ⬇️
StaticClassLiteral<'db>::explicit_bases_ 86.40kB 0.00B -100.00% (86.40kB) ⬇️
explicit_bases_inner 0.00B 70.42kB +70.42kB (new) ⬇️
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 60.66kB 0.00B -100.00% (60.66kB) ⬇️
StaticClassLiteral<'db>::is_typed_dict_ 60.30kB 0.00B -100.00% (60.30kB) ⬇️
inherited_legacy_generic_context_inner 0.00B 45.05kB +45.05kB (new) ⬇️
is_typed_dict_inner 0.00B 42.91kB +42.91kB (new) ⬇️
StaticClassLiteral<'db>::inheritance_cycle_ 39.69kB 0.00B -100.00% (39.69kB) ⬇️
... 35 more

sphinx

Name Old New Diff Outcome
infer_expression_types_impl 19.68MB 19.25MB -2.21% (444.48kB) ⬇️
Type<'db>::class_member_with_policy_ 5.45MB 5.06MB -7.10% (396.33kB) ⬇️
StaticClassLiteral<'db>::try_metaclass_ 359.83kB 0.00B -100.00% (359.83kB) ⬇️
infer_definition_types 20.64MB 20.32MB -1.58% (334.00kB) ⬇️
member_lookup_with_policy_inner 6.65MB 6.34MB -4.75% (323.58kB) ⬇️
infer_scope_types_impl 12.87MB 12.56MB -2.42% (319.38kB) ⬇️
infer_deferred_types 4.20MB 3.89MB -7.35% (315.81kB) ⬇️
try_metaclass_inner 0.00B 238.61kB +238.61kB (new) ⬇️
StaticClassLiteral<'db>::explicit_bases_ 174.23kB 0.00B -100.00% (174.23kB) ⬇️
StaticClassLiteral<'db>::is_typed_dict_ 163.80kB 0.00B -100.00% (163.80kB) ⬇️
explicit_bases_inner 0.00B 138.67kB +138.67kB (new) ⬇️
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 125.15kB 0.00B -100.00% (125.15kB) ⬇️
is_typed_dict_inner 0.00B 120.67kB +120.67kB (new) ⬇️
StaticClassLiteral<'db>::inheritance_cycle_ 100.14kB 0.00B -100.00% (100.14kB) ⬇️
inherited_legacy_generic_context_inner 0.00B 89.59kB +89.59kB (new) ⬇️
... 45 more

prefect

Name Old New Diff Outcome
infer_definition_types 77.83MB 75.86MB -2.53% (1.97MB) ⬇️
infer_expression_types_impl 54.81MB 53.43MB -2.52% (1.38MB) ⬇️
StaticClassLiteral<'db>::try_metaclass_ 1.35MB 0.00B -100.00% (1.35MB) ⬇️
Type<'db>::class_member_with_policy_ 12.07MB 10.86MB -10.09% (1.22MB) ⬇️
infer_scope_types_impl 48.84MB 47.82MB -2.09% (1.02MB) ⬇️
member_lookup_with_policy_inner 15.47MB 14.47MB -6.47% (1.00MB) ⬇️
try_metaclass_inner 0.00B 809.57kB +809.57kB (new) ⬇️
StaticClassLiteral<'db>::explicit_bases_ 635.15kB 0.00B -100.00% (635.15kB) ⬇️
StaticClassLiteral<'db>::is_typed_dict_ 591.34kB 0.00B -100.00% (591.34kB) ⬇️
infer_deferred_types 9.27MB 8.74MB -5.65% (536.62kB) ⬇️
StaticClassLiteral<'db>::inherited_legacy_generic_context_ 499.20kB 0.00B -100.00% (499.20kB) ⬇️
explicit_bases_inner 0.00B 457.41kB +457.41kB (new) ⬇️
StaticClassLiteral<'db>::inheritance_cycle_ 386.23kB 0.00B -100.00% (386.23kB) ⬇️
is_typed_dict_inner 0.00B 379.96kB +379.96kB (new) ⬇️
code_generator_of_static_class 1.96MB 1.61MB -17.53% (351.03kB) ⬇️
... 43 more

@astral-sh-bot

astral-sh-bot Bot commented Jun 6, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@codspeed-hq

codspeed-hq Bot commented Jun 6, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 7.71%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
✅ 66 untouched benchmarks
⏩ 60 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ty_micro[large_union_narrowing] 332.5 ms 308.7 ms +7.71%

Tip

Curious why this is faster? Use the CodSpeed MCP and ask your agent.


Comparing charlie/avoid-caching-trivial-class-headers (a6d3142) with main (3e70e4a)

Open in CodSpeed

Footnotes

  1. 60 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@charliermarsh charliermarsh force-pushed the charlie/avoid-caching-trivial-class-headers branch from 6257a4b to d20901b Compare June 6, 2026 03:10
@charliermarsh charliermarsh force-pushed the charlie/avoid-caching-trivial-class-headers branch from d20901b to a6d3142 Compare June 6, 2026 03:36
@charliermarsh charliermarsh marked this pull request as ready for review June 6, 2026 03:45
@charliermarsh charliermarsh merged commit 12095e9 into main Jun 6, 2026
57 of 58 checks passed
@charliermarsh charliermarsh deleted the charlie/avoid-caching-trivial-class-headers branch June 6, 2026 03:45
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