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

Skip to content

[ty] Avoid caching trivial member lookups#25661

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/avoid-caching-trivial-member-lookups
Jun 5, 2026
Merged

[ty] Avoid caching trivial member lookups#25661
charliermarsh merged 1 commit into
mainfrom
charlie/avoid-caching-trivial-member-lookups

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 5, 2026

Copy link
Copy Markdown
Member

Summary

member_lookup_with_policy currently creates and retains a Salsa query even when the result is known before attribute lookup: for __class__, and for dynamic, divergent, and Never types.

This change handles those cases before entering the tracked query. Materialized divergent fallbacks and the existing __class__ ordering are preserved; all other lookups continue through the unchanged tracked implementation.

@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.54MB -0.26% (103.85kB) ⬇️
trio 98.96MB 98.18MB -0.78% (795.46kB) ⬇️
sphinx 237.91MB 236.75MB -0.49% (1.16MB) ⬇️
prefect 653.76MB 647.82MB -0.91% (5.94MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
Type<'db>::member_lookup_with_policy_ 541.01kB 0.00B -100.00% (541.01kB) ⬇️
Type<'db>::member_lookup_with_policy_inner_ 0.00B 517.13kB +517.13kB (new) ⬇️
Type<'db>::member_lookup_with_policy_::interned_arguments 233.19kB 0.00B -100.00% (233.19kB) ⬇️
Type<'db>::member_lookup_with_policy_inner_::interned_arguments 0.00B 196.32kB +196.32kB (new) ⬇️
infer_expression_types_impl 1.03MB 1.00MB -2.33% (24.49kB) ⬇️
infer_definition_types 1.62MB 1.61MB -0.53% (8.84kB) ⬇️
infer_scope_types_impl 844.35kB 838.11kB -0.74% (6.23kB) ⬇️
function_known_decorators 151.46kB 148.72kB -1.81% (2.74kB) ⬇️
infer_deferred_types 499.45kB 499.17kB -0.06% (288.00B) ⬇️
infer_expression_type_impl 115.12kB 114.91kB -0.18% (216.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 45.75kB 45.64kB -0.26% (120.00B) ⬇️
all_narrowing_constraints_for_expression 105.39kB 105.32kB -0.07% (72.00B) ⬇️
all_negative_narrowing_constraints_for_expression 101.76kB 101.69kB -0.07% (72.00B) ⬇️
infer_statement_types_impl 42.56kB 42.51kB -0.11% (48.00B) ⬇️

trio

Name Old New Diff Outcome
Type<'db>::member_lookup_with_policy_ 1.88MB 0.00B -100.00% (1.88MB) ⬇️
Type<'db>::member_lookup_with_policy_inner_ 0.00B 1.79MB +1.79MB (new) ⬇️
Type<'db>::member_lookup_with_policy_::interned_arguments 908.48kB 0.00B -100.00% (908.48kB) ⬇️
Type<'db>::member_lookup_with_policy_inner_::interned_arguments 0.00B 775.73kB +775.73kB (new) ⬇️
infer_expression_types_impl 6.74MB 6.47MB -4.01% (276.76kB) ⬇️
infer_definition_types 6.89MB 6.78MB -1.68% (118.92kB) ⬇️
infer_expression_type_impl 1.47MB 1.41MB -4.43% (66.75kB) ⬇️
infer_scope_types_impl 4.08MB 4.03MB -1.37% (57.28kB) ⬇️
infer_deferred_types 2.05MB 2.03MB -0.60% (12.61kB) ⬇️
all_narrowing_constraints_for_expression 696.46kB 685.84kB -1.52% (10.62kB) ⬇️
all_negative_narrowing_constraints_for_expression 662.71kB 652.35kB -1.56% (10.36kB) ⬇️
loop_header_reachability 135.36kB 128.21kB -5.28% (7.15kB) ⬇️
function_known_decorators 297.10kB 292.18kB -1.66% (4.92kB) ⬇️
StaticClassLiteral<'db>::decorators_ 77.69kB 75.51kB -2.81% (2.18kB) ⬇️
infer_unpack_types 165.48kB 163.98kB -0.91% (1.50kB) ⬇️
... 12 more

sphinx

Name Old New Diff Outcome
Type<'db>::member_lookup_with_policy_ 7.04MB 0.00B -100.00% (7.04MB) ⬇️
Type<'db>::member_lookup_with_policy_inner_ 0.00B 6.88MB +6.88MB (new) ⬇️
Type<'db>::member_lookup_with_policy_::interned_arguments 2.74MB 0.00B -100.00% (2.74MB) ⬇️
Type<'db>::member_lookup_with_policy_inner_::interned_arguments 0.00B 2.51MB +2.51MB (new) ⬇️
infer_expression_types_impl 20.84MB 20.44MB -1.92% (408.97kB) ⬇️
infer_definition_types 21.31MB 21.13MB -0.88% (191.02kB) ⬇️
infer_scope_types_impl 13.21MB 13.16MB -0.35% (47.93kB) ⬇️
function_known_decorators 1.02MB 1000.80kB -4.33% (45.26kB) ⬇️
infer_deferred_types 4.67MB 4.63MB -0.93% (44.65kB) ⬇️
infer_expression_type_impl 2.94MB 2.92MB -0.63% (19.03kB) ⬇️
all_narrowing_constraints_for_expression 2.69MB 2.68MB -0.26% (7.12kB) ⬇️
all_negative_narrowing_constraints_for_expression 2.61MB 2.60MB -0.27% (7.12kB) ⬇️
loop_header_reachability 357.28kB 351.63kB -1.58% (5.65kB) ⬇️
infer_statement_types_impl 489.35kB 487.85kB -0.31% (1.50kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 708.18kB 707.24kB -0.13% (960.00B) ⬇️
... 5 more

prefect

Name Old New Diff Outcome
Type<'db>::member_lookup_with_policy_ 16.69MB 0.00B -100.00% (16.69MB) ⬇️
Type<'db>::member_lookup_with_policy_inner_ 0.00B 16.27MB +16.27MB (new) ⬇️
Type<'db>::member_lookup_with_policy_::interned_arguments 6.46MB 0.00B -100.00% (6.46MB) ⬇️
Type<'db>::member_lookup_with_policy_inner_::interned_arguments 0.00B 5.84MB +5.84MB (new) ⬇️
infer_expression_types_impl 59.17MB 57.02MB -3.63% (2.15MB) ⬇️
infer_definition_types 82.05MB 80.27MB -2.17% (1.78MB) ⬇️
infer_scope_types_impl 50.36MB 49.92MB -0.88% (453.54kB) ⬇️
function_known_decorators 4.17MB 4.02MB -3.53% (150.35kB) ⬇️
infer_deferred_types 10.27MB 10.13MB -1.40% (146.88kB) ⬇️
infer_expression_type_impl 8.35MB 8.23MB -1.35% (115.15kB) ⬇️
all_narrowing_constraints_for_expression 8.44MB 8.41MB -0.45% (39.00kB) ⬇️
all_negative_narrowing_constraints_for_expression 8.26MB 8.22MB -0.46% (38.70kB) ⬇️
loop_header_reachability 465.77kB 448.17kB -3.78% (17.60kB) ⬇️
infer_statement_types_impl 955.46kB 946.70kB -0.92% (8.77kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 1.04MB 1.03MB -0.61% (6.47kB) ⬇️
... 17 more

@charliermarsh charliermarsh added the performance Potential performance improvement label Jun 5, 2026
@charliermarsh charliermarsh marked this pull request as ready for review June 5, 2026 14:58
@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 draft June 5, 2026 15:03
@charliermarsh charliermarsh marked this pull request as ready for review June 5, 2026 15:08
@charliermarsh charliermarsh marked this pull request as draft June 5, 2026 15:17
@charliermarsh charliermarsh marked this pull request as ready for review June 5, 2026 15:24
heap_size=ruff_memory_usage::heap_size
)]
pub(crate) fn member_lookup_with_policy(
fn member_lookup_with_policy_inner(

@AlexWaygood AlexWaygood Jun 5, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's no valid reason for this function ever to be called outside of its single callsite, I would make it a nested function inside member_lookup_with_policy, and remove the special case regarding __class__ from the body of the function. (The special case is now handled by the wrapper function that calls it.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit mixed on whether this is worth the churn (though I'll remove the special-case).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

personaly I think so -- it's what we do in a bunch of other places where we have similar situations. the fact that there's an inner Salsa-tracked function that's wrapped by an outer non-tracked function is an implementation detail that callers shouldn't have to worry about and that shouldn't impact the autocomplete suggestions I get in VSCode, etc

@charliermarsh charliermarsh merged commit af52481 into main Jun 5, 2026
59 checks passed
@charliermarsh charliermarsh deleted the charlie/avoid-caching-trivial-member-lookups branch June 5, 2026 16:54
charliermarsh added a commit that referenced this pull request Jun 5, 2026
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