Skip to content

[ty] Compact retained member lookup keys#25776

Open
charliermarsh wants to merge 1 commit into
mainfrom
charlie/compact-member-lookup-keys
Open

[ty] Compact retained member lookup keys#25776
charliermarsh wants to merge 1 commit into
mainfrom
charlie/compact-member-lookup-keys

Conversation

@charliermarsh

Copy link
Copy Markdown
Member

Summary

class_member_with_policy and member_lookup_with_policy_inner currently retain the full Salsa argument set for every lookup, even though almost all calls use the default policy, do not need a separate receiver, and many class-member lookups request __get__.

This change routes those common cases through narrower tracked queries. Default class lookups no longer retain a policy, __get__ lookups no longer retain a name or policy, and default instance lookups no longer retain a policy or absent receiver. Non-default policies and explicit receivers continue through dedicated tracked queries, and all paths share the existing lookup implementation and cycle handling.

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

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

@astral-sh-bot

astral-sh-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 35.37MB 35.32MB -0.13% (45.35kB) ⬇️
trio 87.84MB 87.67MB -0.20% (175.50kB) ⬇️
sphinx 207.60MB 206.96MB -0.31% (656.28kB) ⬇️
prefect 564.52MB 562.88MB -0.29% (1.64MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
member_lookup_with_policy_inner 404.40kB 63.38kB -84.33% (341.02kB) ⬇️
member_lookup_inner 0.00B 339.69kB +339.69kB (new) ⬇️
Type<'db>::class_member_with_policy_ 316.53kB 0.00B -100.00% (316.53kB) ⬇️
Type<'db>::class_member_inner_ 0.00B 200.85kB +200.85kB (new) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 163.41kB 0.00B -100.00% (163.41kB) ⬇️
member_lookup_with_policy_inner::interned_arguments 201.68kB 54.54kB -72.96% (147.14kB) ⬇️
member_lookup_inner::interned_arguments 0.00B 110.44kB +110.44kB (new) ⬇️
Type<'db>::class_member_with_policy_inner_ 0.00B 109.54kB +109.54kB (new) ⬇️
Type<'db>::class_member_inner_::interned_arguments 0.00B 96.84kB +96.84kB (new) ⬇️
Type<'db>::class_member_with_policy_inner_::interned_arguments 0.00B 54.34kB +54.34kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_ 0.00B 6.14kB +6.14kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_::interned_arguments 0.00B 2.88kB +2.88kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner 0.00B 1.34kB +1.34kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner::interned_arguments 0.00B 720.00B +720.00B (new) ⬇️

trio

Name Old New Diff Outcome
member_lookup_with_policy_inner 1.42MB 260.07kB -82.06% (1.16MB) ⬇️
Type<'db>::class_member_with_policy_ 1.15MB 0.00B -100.00% (1.15MB) ⬇️
member_lookup_inner 0.00B 1.13MB +1.13MB (new) ⬇️
Type<'db>::class_member_inner_ 0.00B 700.88kB +700.88kB (new) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 616.59kB 0.00B -100.00% (616.59kB) ⬇️
member_lookup_with_policy_inner::interned_arguments 767.46kB 212.37kB -72.33% (555.09kB) ⬇️
Type<'db>::class_member_with_policy_inner_ 0.00B 425.31kB +425.31kB (new) ⬇️
member_lookup_inner::interned_arguments 0.00B 407.44kB +407.44kB (new) ⬇️
Type<'db>::class_member_inner_::interned_arguments 0.00B 351.94kB +351.94kB (new) ⬇️
Type<'db>::class_member_with_policy_inner_::interned_arguments 0.00B 210.23kB +210.23kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_ 0.00B 48.47kB +48.47kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner 0.00B 28.97kB +28.97kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_::interned_arguments 0.00B 17.37kB +17.37kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner::interned_arguments 0.00B 13.12kB +13.12kB (new) ⬇️
infer_expression_types_impl 6.57MB 6.57MB -0.01% (984.00B) ⬇️
... 6 more

sphinx

Name Old New Diff Outcome
member_lookup_with_policy_inner 5.64MB 593.31kB -89.72% (5.06MB) ⬇️
member_lookup_inner 0.00B 4.97MB +4.97MB (new) ⬇️
Type<'db>::class_member_with_policy_ 4.63MB 0.00B -100.00% (4.63MB) ⬇️
Type<'db>::class_member_inner_ 0.00B 3.47MB +3.47MB (new) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 2.29MB 0.00B -100.00% (2.29MB) ⬇️
member_lookup_with_policy_inner::interned_arguments 2.66MB 497.86kB -81.72% (2.17MB) ⬇️
member_lookup_inner::interned_arguments 0.00B 1.65MB +1.65MB (new) ⬇️
Type<'db>::class_member_inner_::interned_arguments 0.00B 1.61MB +1.61MB (new) ⬇️
Type<'db>::class_member_with_policy_inner_ 0.00B 1.03MB +1.03MB (new) ⬇️
Type<'db>::class_member_with_policy_inner_::interned_arguments 0.00B 495.12kB +495.12kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_ 0.00B 128.44kB +128.44kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner 0.00B 88.18kB +88.18kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_::interned_arguments 0.00B 43.66kB +43.66kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner::interned_arguments 0.00B 36.21kB +36.21kB (new) ⬇️
CallableType 1.36MB 1.36MB -0.02% (304.00B) ⬇️
... 4 more

prefect

Name Old New Diff Outcome
member_lookup_with_policy_inner 13.53MB 1.08MB -91.99% (12.45MB) ⬇️
member_lookup_inner 0.00B 12.26MB +12.26MB (new) ⬇️
Type<'db>::class_member_with_policy_ 10.02MB 0.00B -100.00% (10.02MB) ⬇️
Type<'db>::class_member_inner_ 0.00B 7.61MB +7.61MB (new) ⬇️
member_lookup_with_policy_inner::interned_arguments 6.68MB 962.10kB -85.93% (5.74MB) ⬇️
Type<'db>::class_member_with_policy_::interned_arguments 5.68MB 0.00B -100.00% (5.68MB) ⬇️
member_lookup_inner::interned_arguments 0.00B 4.41MB +4.41MB (new) ⬇️
Type<'db>::class_member_inner_::interned_arguments 0.00B 4.23MB +4.23MB (new) ⬇️
Type<'db>::class_member_with_policy_inner_ 0.00B 2.04MB +2.04MB (new) ⬇️
Type<'db>::class_member_with_policy_inner_::interned_arguments 0.00B 949.71kB +949.71kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_ 0.00B 378.02kB +378.02kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner 0.00B 191.88kB +191.88kB (new) ⬇️
Type<'db>::class_member_dunder_get_inner_::interned_arguments 0.00B 113.48kB +113.48kB (new) ⬇️
member_lookup_with_policy_and_receiver_inner::interned_arguments 0.00B 83.55kB +83.55kB (new) ⬇️
infer_expression_types_impl 55.21MB 55.21MB +0.00% (2.40kB) ⬇️
... 10 more

@astral-sh-bot

astral-sh-bot Bot commented Jun 9, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Flaky changes detected. This PR summary excludes flaky changes; see the HTML report for details.

Full report with detailed diff (timing results)

@charliermarsh

Copy link
Copy Markdown
Member Author

This seems plausibly good to me given that it also has a positive effect on the multi-threaded benchmark.

@charliermarsh charliermarsh marked this pull request as ready for review June 9, 2026 13:03
@charliermarsh charliermarsh added the performance Potential performance improvement label Jun 9, 2026

@carljm carljm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks fine. It does seem like it has a small but definite memory improvement. Not convinced there's a meaningful perf impact, from looking at CodSpeed and ecosystem timings. I would say for me this seems right on the bubble of "worth it", but I don't object to landing it.

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.

2 participants