Skip to content

[ty] Defer union of parameter types#24756

Merged
charliermarsh merged 2 commits intomainfrom
charlie/ty-1393-performance-iii
Apr 21, 2026
Merged

[ty] Defer union of parameter types#24756
charliermarsh merged 2 commits intomainfrom
charlie/ty-1393-performance-iii

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Apr 20, 2026

Summary

On main, given a variadic argument like *args, we construct an accumulated union of all parameters passed to the call, updating that union one-by-one as we go. So for each argument, we rebuild the union.

Now, we store a union builder per parameter, and build those unions at the end.

@astral-sh-bot astral-sh-bot Bot added the ty Multi-file analysis & type inference label Apr 20, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 20, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.36%. The number of fully passing files held steady at 79/133.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 20, 2026

Memory usage report

Summary

Project Old New Diff Outcome
flake8 47.94MB 47.86MB -0.16% (80.90kB) ⬇️
trio 117.65MB 117.33MB -0.27% (327.37kB) ⬇️
sphinx 262.78MB 261.45MB -0.50% (1.33MB) ⬇️
prefect 718.18MB 713.80MB -0.61% (4.39MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
UnionType<'db>::from_two_elements_ 74.58kB 28.28kB -62.08% (46.30kB) ⬇️
UnionType<'db>::from_two_elements_::interned_arguments 47.44kB 15.47kB -67.39% (31.97kB) ⬇️
UnionType 89.45kB 77.44kB -13.43% (12.02kB) ⬇️
infer_expression_types_impl 1.04MB 1.04MB +0.37% (3.98kB) ⬇️
infer_definition_types 1.86MB 1.87MB +0.15% (2.79kB) ⬇️
infer_scope_types_impl 986.36kB 987.34kB +0.10% (1008.00B) ⬇️
function_known_decorators 319.14kB 319.77kB +0.19% (636.00B) ⬇️
infer_deferred_types 693.74kB 694.36kB +0.09% (636.00B) ⬇️
Type<'db>::try_call_dunder_get_ 368.19kB 368.58kB +0.11% (396.00B) ⬇️

trio

Name Old New Diff Outcome
UnionType<'db>::from_two_elements_ 272.75kB 41.36kB -84.84% (231.39kB) ⬇️
UnionType<'db>::from_two_elements_::interned_arguments 163.54kB 39.36kB -75.93% (124.18kB) ⬇️
infer_expression_types_impl 7.01MB 7.04MB +0.49% (35.20kB) ⬇️
UnionType 285.66kB 258.03kB -9.67% (27.62kB) ⬇️
Type<'db>::try_call_dunder_get_ 1.34MB 1.35MB +0.72% (9.89kB) ⬇️
infer_scope_types_impl 4.75MB 4.75MB +0.12% (5.99kB) ⬇️
infer_expression_type_impl 1.30MB 1.31MB +0.11% (1.41kB) ⬇️
StaticClassLiteral<'db>::try_metaclass_ 139.61kB 140.46kB +0.60% (864.00B) ⬇️
all_narrowing_constraints_for_expression 591.07kB 591.83kB +0.13% (780.00B) ⬇️
function_known_decorators 922.48kB 923.09kB +0.07% (624.00B) ⬇️
infer_deferred_types 2.34MB 2.34MB +0.03% (624.00B) ⬇️
loop_header_reachability 130.03kB 130.60kB +0.44% (588.00B) ⬇️
infer_unpack_types 143.38kB 143.05kB -0.23% (336.00B) ⬇️
infer_definition_types 7.58MB 7.58MB +0.00% (168.00B) ⬇️
all_negative_narrowing_constraints_for_expression 184.47kB 184.62kB +0.08% (156.00B) ⬇️
... 2 more

sphinx

Name Old New Diff Outcome
UnionType<'db>::from_two_elements_ 1.21MB 279.50kB -77.36% (955.28kB) ⬇️
UnionType<'db>::from_two_elements_::interned_arguments 691.80kB 135.18kB -80.46% (556.62kB) ⬇️
UnionType 1.07MB 947.42kB -13.46% (147.41kB) ⬇️
infer_expression_types_impl 20.76MB 20.87MB +0.57% (121.05kB) ⬇️
infer_scope_types_impl 15.43MB 15.51MB +0.52% (82.09kB) ⬇️
infer_definition_types 23.63MB 23.68MB +0.20% (48.62kB) ⬇️
Type<'db>::try_call_dunder_get_ 4.88MB 4.91MB +0.64% (31.85kB) ⬇️
function_known_decorators 2.46MB 2.47MB +0.36% (9.01kB) ⬇️
infer_deferred_types 5.53MB 5.54MB +0.16% (9.01kB) ⬇️
loop_header_reachability 364.45kB 364.06kB -0.11% (396.00B) ⬇️
infer_expression_type_impl 2.90MB 2.90MB -0.01% (324.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 2.36MB 2.36MB +0.01% (324.00B) ⬇️
Type<'db>::member_lookup_with_policy_ 6.85MB 6.85MB +0.00% (324.00B) ⬇️
all_negative_narrowing_constraints_for_expression 1.00MB 1.00MB -0.01% (120.00B) ⬇️
all_narrowing_constraints_for_expression 2.34MB 2.34MB +0.00% (72.00B) ⬇️
... 1 more

prefect

Name Old New Diff Outcome
UnionType<'db>::from_two_elements_ 4.52MB 969.28kB -79.07% (3.57MB) ⬇️
UnionType<'db>::from_two_elements_::interned_arguments 2.10MB 356.55kB -83.45% (1.76MB) ⬇️
UnionType 3.01MB 2.43MB -19.44% (599.77kB) ⬇️
infer_definition_types 90.55MB 91.12MB +0.62% (576.18kB) ⬇️
infer_expression_types_impl 63.13MB 63.51MB +0.60% (388.91kB) ⬇️
infer_scope_types_impl 54.92MB 55.17MB +0.44% (247.75kB) ⬇️
Type<'db>::try_call_dunder_get_ 10.64MB 10.84MB +1.89% (205.89kB) ⬇️
infer_expression_type_impl 13.43MB 13.47MB +0.31% (42.25kB) ⬇️
function_known_decorators 8.28MB 8.31MB +0.33% (27.80kB) ⬇️
infer_deferred_types 14.62MB 14.65MB +0.18% (27.00kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 10.08MB 10.10MB +0.17% (17.59kB) ⬇️
Type<'db>::member_lookup_with_policy_ 17.27MB 17.28MB +0.07% (12.25kB) ⬇️
all_narrowing_constraints_for_expression 7.21MB 7.22MB +0.12% (8.86kB) ⬇️
Type<'db>::class_member_with_policy_ 17.67MB 17.68MB +0.04% (6.73kB) ⬇️
all_negative_narrowing_constraints_for_expression 2.63MB 2.64MB +0.14% (3.82kB) ⬇️
... 11 more

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 20, 2026

Merging this PR will improve performance by ×17

⚠️ 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

⚡ 4 improved benchmarks
✅ 49 untouched benchmarks
⏩ 60 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation ty_micro[vararg_parameter_type_accumulation] 4,875.3 ms 282.8 ms ×17
Simulation ty_micro[gradual_vararg_call] 4,871.2 ms 287.2 ms ×17
Memory ty_micro[gradual_vararg_call] 162.1 MB 34.5 MB ×4.7
Memory ty_micro[vararg_parameter_type_accumulation] 161 MB 33.4 MB ×4.8

Comparing charlie/ty-1393-performance-iii (93501b2) with charlie/ty-1393-performance-i (c474889)

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.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented Apr 20, 2026

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 charliermarsh added the performance Potential performance improvement label Apr 20, 2026
@charliermarsh charliermarsh marked this pull request as ready for review April 20, 2026 20:49
@carljm carljm removed their request for review April 20, 2026 20:56
Base automatically changed from charlie/ty-1393-performance-i to main April 21, 2026 16:30
@charliermarsh charliermarsh merged commit fe3e821 into main Apr 21, 2026
104 checks passed
@charliermarsh charliermarsh deleted the charlie/ty-1393-performance-iii branch April 21, 2026 16:31
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