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

Skip to content

[ty] Use same-file expression inference in reachability#25694

Merged
charliermarsh merged 1 commit into
mainfrom
codex/ty-same-file-reachability
Jun 6, 2026
Merged

[ty] Use same-file expression inference in reachability#25694
charliermarsh merged 1 commit into
mainfrom
codex/ty-same-file-reachability

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Jun 6, 2026

Copy link
Copy Markdown
Member

Summary

Reachability currently calls infer_expression_type for each expression that it evaluates. This creates and retains a separate Salsa query for every expression, even though reachability only evaluates predicates from the same file as the enclosing query.

This uses infer_same_file_expression_type instead. The underlying infer_expression_types query continues to provide caching and cycle recovery, while cross-file callers continue through infer_expression_type; reachability avoids retaining the redundant single-expression query layer.

Across the memory-report projects, retained infer_expression_type_impl memory fell by 88% to 95%, reducing total retained memory by 0.15% to 0.68% without diagnostic changes.

@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.24MB -0.15% (56.62kB) ⬇️
sphinx 221.10MB 220.51MB -0.27% (601.12kB) ⬇️
trio 93.75MB 93.12MB -0.66% (637.72kB) ⬇️
prefect 605.82MB 601.71MB -0.68% (4.11MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
infer_expression_type_impl 113.82kB 14.02kB -87.68% (99.79kB) ⬇️
infer_expression_types_impl 984.51kB 1015.79kB +3.18% (31.28kB) ⬇️
infer_definition_types 1.58MB 1.59MB +0.36% (5.84kB) ⬇️
infer_scope_types_impl 818.46kB 821.73kB +0.40% (3.27kB) ⬇️
place_by_id 141.12kB 141.64kB +0.37% (528.00B) ⬇️
infer_deferred_types 456.35kB 456.83kB +0.11% (492.00B) ⬇️
loop_header_reachability 12.20kB 12.67kB +3.81% (476.00B) ⬇️
infer_statement_types_impl 40.43kB 40.82kB +0.99% (408.00B) ⬇️
function_known_decorators 147.23kB 147.60kB +0.25% (372.00B) ⬇️
cached_protocol_interface 56.50kB 56.67kB +0.31% (180.00B) ⬇️
ClassType<'db>::abstract_methods_ 2.29kB 2.39kB +4.62% (108.00B) ⬇️
overloads_and_implementation_inner 79.39kB 79.47kB +0.10% (84.00B) ⬇️
enum_metadata 61.70kB 61.77kB +0.11% (72.00B) ⬇️
member_lookup_with_policy_inner 500.30kB 500.36kB +0.01% (60.00B) ⬇️
all_narrowing_constraints_for_expression 168.72kB 168.76kB +0.02% (40.00B) ⬇️
... 1 more

sphinx

Name Old New Diff Outcome
infer_expression_type_impl 2.88MB 282.79kB -90.40% (2.60MB) ⬇️
infer_expression_types_impl 19.68MB 21.18MB +7.60% (1.50MB) ⬇️
infer_definition_types 20.64MB 21.00MB +1.74% (368.15kB) ⬇️
infer_scope_types_impl 12.87MB 12.97MB +0.74% (97.29kB) ⬇️
loop_header_reachability 339.81kB 357.30kB +5.15% (17.49kB) ⬇️
member_lookup_with_policy_inner 6.65MB 6.67MB +0.25% (16.94kB) ⬇️
place_by_id 1.37MB 1.38MB +0.79% (11.18kB) ⬇️
infer_statement_types_impl 460.91kB 468.47kB +1.64% (7.56kB) ⬇️
all_narrowing_constraints_for_expression 4.19MB 4.19MB +0.12% (5.13kB) ⬇️
infer_deferred_types 4.20MB 4.20MB +0.04% (1.83kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 703.07kB 704.43kB +0.19% (1.36kB) ⬇️
function_known_decorators 987.44kB 988.64kB +0.12% (1.20kB) ⬇️
ClassType<'db>::abstract_methods_ 18.08kB 18.71kB +3.50% (648.00B) ⬇️
overloads_and_implementation_inner 770.36kB 770.81kB +0.06% (468.00B) ⬇️
analyze_pattern_predicate 1.98kB 2.29kB +15.38% (312.00B) ⬇️
... 8 more

trio

Name Old New Diff Outcome
infer_expression_type_impl 1.37MB 64.15kB -95.43% (1.31MB) ⬇️
infer_expression_types_impl 6.27MB 6.81MB +8.54% (548.75kB) ⬇️
infer_definition_types 6.63MB 6.70MB +1.05% (71.37kB) ⬇️
infer_scope_types_impl 3.91MB 3.96MB +1.23% (49.09kB) ⬇️
place_by_id 557.51kB 568.54kB +1.98% (11.03kB) ⬇️
loop_header_reachability 124.76kB 130.45kB +4.56% (5.69kB) ⬇️
infer_deferred_types 1.87MB 1.87MB +0.25% (4.71kB) ⬇️
function_known_decorators 290.61kB 293.87kB +1.12% (3.26kB) ⬇️
all_narrowing_constraints_for_expression 1023.59kB 1.00MB +0.30% (3.05kB) ⬇️
member_lookup_with_policy_inner 1.74MB 1.74MB +0.05% (936.00B) ⬇️
ClassType<'db>::abstract_methods_ 33.28kB 34.05kB +2.32% (792.00B) ⬇️
cached_protocol_interface 140.58kB 141.13kB +0.39% (564.00B) ⬇️
infer_statement_types_impl 47.11kB 47.66kB +1.17% (564.00B) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 123.91kB 124.38kB +0.38% (476.00B) ⬇️
overloads_and_implementation_inner 327.03kB 327.41kB +0.12% (396.00B) ⬇️
... 9 more

prefect

Name Old New Diff Outcome
infer_expression_type_impl 8.08MB 404.91kB -95.11% (7.69MB) ⬇️
infer_expression_types_impl 54.81MB 57.47MB +4.86% (2.66MB) ⬇️
infer_definition_types 77.83MB 78.46MB +0.80% (635.73kB) ⬇️
infer_scope_types_impl 48.84MB 49.07MB +0.46% (230.54kB) ⬇️
loop_header_reachability 435.38kB 449.81kB +3.31% (14.43kB) ⬇️
function_known_decorators 3.97MB 3.98MB +0.25% (10.07kB) ⬇️
all_narrowing_constraints_for_expression 13.33MB 13.34MB +0.07% (9.98kB) ⬇️
infer_deferred_types 9.27MB 9.28MB +0.09% (8.55kB) ⬇️
infer_statement_types_impl 886.24kB 893.93kB +0.87% (7.69kB) ⬇️
member_lookup_with_policy_inner 15.47MB 15.48MB +0.03% (4.22kB) ⬇️
place_by_id 5.04MB 5.05MB +0.08% (3.95kB) ⬇️
ClassType<'db>::abstract_methods_ 145.64kB 148.20kB +1.75% (2.55kB) ⬇️
cached_protocol_interface 534.27kB 536.71kB +0.46% (2.44kB) ⬇️
StaticClassLiteral<'db>::implicit_attribute_inner_ 1.02MB 1.02MB +0.18% (1.88kB) ⬇️
infer_unpack_types 1.07MB 1.07MB +0.07% (744.00B) ⬇️
... 14 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 not alter performance

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

⚡ 2 improved benchmarks
❌ 2 regressed benchmarks
✅ 63 untouched benchmarks
⏩ 60 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory ty_micro[typevar_mapping_small_accumulations] 13.3 MB 14 MB -5.26%
Simulation ty_micro[typevar_mapping_small_accumulations] 210.2 ms 219.3 ms -4.16%
Simulation ty_check_file[incremental] 8.1 ms 7.6 ms +6%
Memory ty_micro[typeis_narrowing] 20 MB 19 MB +4.89%

Tip

Investigate this regression with the CodSpeed MCP and your agent.


Comparing codex/ty-same-file-reachability (1f837a4) 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 added the performance Potential performance improvement label Jun 6, 2026
@charliermarsh charliermarsh marked this pull request as ready for review June 6, 2026 03:43
@charliermarsh charliermarsh merged commit ad70d50 into main Jun 6, 2026
58 of 59 checks passed
@charliermarsh charliermarsh deleted the codex/ty-same-file-reachability branch June 6, 2026 17:57
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