Skip to content

[ty] Avoid storing redundant reachability indexes#25453

Merged
charliermarsh merged 1 commit into
mainfrom
charlie/elide-reachability-rank-metadata
May 29, 2026
Merged

[ty] Avoid storing redundant reachability indexes#25453
charliermarsh merged 1 commit into
mainfrom
charlie/elide-reachability-rank-metadata

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented May 29, 2026

Summary

When all reachability nodes for a scope are retained, their IDs already match their positions in the stored node array. In that case, this PR avoids storing an extra bit vector for mapping node IDs back to the array. We only allocate that mapping when unused intermediate nodes were removed.

This reduces retained memory for reachability constraints while preserving the existing compaction for scopes that need it. It also moves node lookup into ReachabilityConstraints::get_interior_node, so both paths use the same lookup logic.

@charliermarsh charliermarsh added the ty Multi-file analysis & type inference label May 29, 2026
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 29, 2026

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 91.94%. The percentage of expected errors that received a diagnostic held steady at 87.09%. The number of fully passing files held steady at 92/134.

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 29, 2026

Memory usage report

Summary

Project Old New Diff Outcome
flake8 45.99MB 45.87MB -0.26% (124.68kB) ⬇️
trio 112.29MB 112.09MB -0.18% (209.21kB) ⬇️
sphinx 264.91MB 264.59MB -0.12% (320.56kB) ⬇️
prefect 715.26MB 714.54MB -0.10% (732.64kB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
semantic_index 13.11MB 12.99MB -0.93% (124.68kB) ⬇️

trio

Name Old New Diff Outcome
semantic_index 28.60MB 28.40MB -0.71% (209.21kB) ⬇️

sphinx

Name Old New Diff Outcome
semantic_index 59.29MB 58.97MB -0.53% (320.56kB) ⬇️

prefect

Name Old New Diff Outcome
semantic_index 179.54MB 178.83MB -0.40% (732.64kB) ⬇️

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 29, 2026

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@charliermarsh charliermarsh force-pushed the charlie/compact-retained-semantic-arrays branch 2 times, most recently from 55b7221 to bedff0d Compare May 29, 2026 14:17
@charliermarsh charliermarsh force-pushed the charlie/elide-reachability-rank-metadata branch from 7356b26 to d9dea8c Compare May 29, 2026 15:11
@charliermarsh charliermarsh changed the title [ty] View memory benchmarks [ty] Elide direct reachability rank metadata May 29, 2026
@charliermarsh charliermarsh changed the base branch from charlie/compact-retained-semantic-arrays to main May 29, 2026 15:12
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 29, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@charliermarsh charliermarsh changed the title [ty] Elide direct reachability rank metadata [ty] Avoid storing redundant reachability indexes May 29, 2026
@charliermarsh
Copy link
Copy Markdown
Member Author

Beyond the memory, 4% perf on Pydantic, 2% on anyio (1% regression on some micro benchmarks).

@charliermarsh charliermarsh marked this pull request as ready for review May 29, 2026 17:03
@astral-sh-bot astral-sh-bot Bot requested a review from oconnor663 May 29, 2026 17:03
@charliermarsh charliermarsh added the performance Potential performance improvement label May 29, 2026
@AlexWaygood
Copy link
Copy Markdown
Member

(the pydantic benchmark seems to have become flaky in the last week or so, regularly reporting speedups or regressions of up to 5% on PRs that couldn't plausibly have had that impact. I suspect some "perf nondeterminism" somewhere... not a knock on your PR, though :-)

@AlexWaygood AlexWaygood removed their request for review May 29, 2026 17:28
@charliermarsh charliermarsh merged commit 5a6c811 into main May 29, 2026
94 of 95 checks passed
@charliermarsh charliermarsh deleted the charlie/elide-reachability-rank-metadata branch May 29, 2026 21:01
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