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

Skip to content

[ty] Defer applying type context to simple standalone expressions#26252

Merged
ibraheemdev merged 1 commit into
mainfrom
ibraheem/standalone-type-context
Jun 23, 2026
Merged

[ty] Defer applying type context to simple standalone expressions#26252
ibraheemdev merged 1 commit into
mainfrom
ibraheem/standalone-type-context

Conversation

@ibraheemdev

Copy link
Copy Markdown
Member

The infer_expression_types query cache inference results uniquely for a given expression and type context. For expressions that are not directly affected by type context, we can defer applying the type context until after the Salsa query runs, allowing us to reuse the memoized query result during multi-inference.

@ibraheemdev ibraheemdev added performance Potential performance improvement ty Multi-file analysis & type inference labels Jun 23, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 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 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.

@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 30.77MB 30.72MB -0.16% (49.27kB) ⬇️
trio 77.50MB 77.42MB -0.11% (86.43kB) ⬇️
sphinx 193.45MB 193.03MB -0.21% (425.33kB) ⬇️
prefect 516.13MB 515.27MB -0.17% (877.72kB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
infer_expression_types_impl 987.68kB 960.04kB -2.80% (27.64kB) ⬇️
ExpressionWithContext 17.66kB 5.86kB -66.81% (11.80kB) ⬇️
parsed_module 9.77MB 9.77MB -0.06% (5.64kB) ⬇️
infer_scope_types_impl 674.68kB 671.88kB -0.42% (2.80kB) ⬇️
infer_definition_types 1.35MB 1.35MB -0.07% (984.00B) ⬇️
infer_statement_types_impl 54.57kB 54.30kB -0.49% (276.00B) ⬇️
loop_header_reachability 12.44kB 12.39kB -0.38% (48.00B) ⬇️
all_narrowing_constraints_for_expression 87.07kB 87.04kB -0.04% (36.00B) ⬇️
infer_expression_type_impl 15.20kB 15.16kB -0.23% (36.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 50.63kB 50.59kB -0.07% (36.00B) ⬇️
member_lookup_with_policy_inner 430.43kB 430.42kB -0.00% (12.00B) ⬇️

trio

Name Old New Diff Outcome
infer_expression_types_impl 6.56MB 6.51MB -0.85% (56.96kB) ⬇️
ExpressionWithContext 36.41kB 13.91kB -61.80% (22.50kB) ⬇️
infer_scope_types_impl 3.20MB 3.19MB -0.16% (5.12kB) ⬇️
infer_definition_types 5.59MB 5.59MB -0.02% (1.42kB) ⬇️
infer_statement_types_impl 56.70kB 56.51kB -0.33% (192.00B) ⬇️
all_narrowing_constraints_for_expression 612.97kB 612.87kB -0.02% (108.00B) ⬇️
loop_header_reachability 124.49kB 124.42kB -0.06% (72.00B) ⬇️
parsed_module 15.03MB 15.03MB +0.00% (40.00B) ⬇️
infer_expression_type_impl 60.77kB 60.73kB -0.06% (36.00B) ⬇️
function_known_decorators 285.42kB 285.39kB -0.01% (24.00B) ⬇️
infer_deferred_types 1.80MB 1.80MB -0.00% (24.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 130.59kB 130.57kB -0.01% (12.00B) ⬇️
member_lookup_with_policy_inner 1.50MB 1.50MB -0.00% (12.00B) ⬇️

sphinx

Name Old New Diff Outcome
infer_expression_types_impl 23.22MB 22.97MB -1.09% (259.75kB) ⬇️
ExpressionWithContext 230.70kB 106.64kB -53.78% (124.06kB) ⬇️
infer_scope_types_impl 10.53MB 10.51MB -0.22% (23.89kB) ⬇️
infer_definition_types 19.55MB 19.54MB -0.04% (8.55kB) ⬇️
infer_statement_types_impl 964.62kB 961.56kB -0.32% (3.06kB) ⬇️
infer_expression_type_impl 279.95kB 277.41kB -0.91% (2.54kB) ⬇️
parsed_module 18.36MB 18.36MB -0.01% (2.05kB) ⬇️
member_lookup_with_policy_inner 6.00MB 6.00MB -0.02% (1.47kB) ⬇️
CallableType 1.47MB 1.47MB +0.02% (304.00B) ⬇️
all_narrowing_constraints_for_expression 2.69MB 2.69MB -0.01% (168.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 780.80kB 780.74kB -0.01% (64.00B) ⬇️
loop_header_reachability 382.14kB 382.13kB -0.00% (12.00B) ⬇️

prefect

Name Old New Diff Outcome
infer_expression_types_impl 56.41MB 55.89MB -0.92% (533.94kB) ⬇️
ExpressionWithContext 495.86kB 236.56kB -52.29% (259.30kB) ⬇️
infer_scope_types_impl 38.88MB 38.84MB -0.11% (42.04kB) ⬇️
infer_definition_types 69.14MB 69.12MB -0.03% (20.02kB) ⬇️
infer_statement_types_impl 1.53MB 1.51MB -0.84% (13.07kB) ⬇️
parsed_module 19.36MB 19.35MB -0.04% (7.38kB) ⬇️
all_narrowing_constraints_for_expression 6.57MB 6.57MB -0.02% (1.02kB) ⬇️
infer_expression_type_impl 383.97kB 383.66kB -0.08% (324.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 1.10MB 1.10MB -0.03% (304.00B) ⬇️
member_lookup_with_policy_inner 14.30MB 14.30MB -0.00% (300.00B) ⬇️
infer_unpack_types 976.62kB 976.50kB -0.01% (120.00B) ⬇️
StaticClassLiteral<'db>::variance_of_::interned_arguments 37.41kB 37.48kB +0.19% (72.00B) ⬇️
loop_header_reachability 428.91kB 428.85kB -0.01% (60.00B) ⬇️
StaticClassLiteral<'db>::variance_of_ 36.50kB 36.55kB +0.13% (48.00B) ⬇️

@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@ibraheemdev ibraheemdev marked this pull request as ready for review June 23, 2026 01:33
@ibraheemdev ibraheemdev requested a review from a team as a code owner June 23, 2026 01:33
@astral-sh-bot astral-sh-bot Bot requested a review from charliermarsh June 23, 2026 01:33
@ibraheemdev

Copy link
Copy Markdown
Member Author

Looks like a small performance and memory usage win across the board. I have some future PRs built upon the can_defer_type_context primitive as well.

@ibraheemdev ibraheemdev merged commit ad41460 into main Jun 23, 2026
61 checks passed
@ibraheemdev ibraheemdev deleted the ibraheem/standalone-type-context branch June 23, 2026 01:39
@AlexWaygood

AlexWaygood commented Jun 23, 2026

Copy link
Copy Markdown
Member

Looks like a small performance and memory usage win across the board.

Hmm, to me it looks like only three microbenchmarks improved, and nine other benchmarks showed small regressions?

IMG_1529

(But to be clear I'm not asking for this to be reverted if you have other things building on this, especially since it also improved memory usage)

@ibraheemdev

Copy link
Copy Markdown
Member Author

Hmm.. sorry, I must have misread those. I'll readdress whether this particular case makes sense after I land the followup work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Potential performance improvement ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants