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

Skip to content

[ty] Consolidate AST ID reverse lookup#25455

Merged
charliermarsh merged 2 commits into
mainfrom
charlie/consolidate-ast-id-map
Jun 1, 2026
Merged

[ty] Consolidate AST ID reverse lookup#25455
charliermarsh merged 2 commits into
mainfrom
charlie/consolidate-ast-id-map

Conversation

@charliermarsh

@charliermarsh charliermarsh commented May 29, 2026

Copy link
Copy Markdown
Member

Summary

Consolidates the per-scope AST ID reverse lookup maps into a single file-level map. IDs are still assigned per scope, preserving stable outer-scope IDs while reducing retained map overhead.

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

astral-sh-bot Bot commented May 29, 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 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

astral-sh-bot Bot commented May 29, 2026

Copy link
Copy Markdown

Memory usage report

Summary

Project Old New Diff Outcome
flake8 43.16MB 42.85MB -0.73% (324.23kB) ⬇️
trio 107.20MB 106.55MB -0.61% (669.29kB) ⬇️
sphinx 256.42MB 255.18MB -0.49% (1.25MB) ⬇️
prefect 691.74MB 687.97MB -0.54% (3.76MB) ⬇️

Significant changes

Click to expand detailed breakdown

flake8

Name Old New Diff Outcome
semantic_index 12.14MB 11.82MB -2.61% (324.23kB) ⬇️

trio

Name Old New Diff Outcome
semantic_index 26.22MB 25.57MB -2.49% (669.29kB) ⬇️

sphinx

Name Old New Diff Outcome
semantic_index 53.93MB 52.69MB -2.31% (1.25MB) ⬇️

prefect

Name Old New Diff Outcome
semantic_index 157.85MB 154.08MB -2.38% (3.76MB) ⬇️

@astral-sh-bot

astral-sh-bot Bot commented May 29, 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 May 29, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 65 untouched benchmarks
⏩ 60 skipped benchmarks1


Comparing charlie/consolidate-ast-id-map (8c28fb0) with main (b82dfe7)

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 force-pushed the charlie/elide-reachability-rank-metadata branch from 7356b26 to d9dea8c Compare May 29, 2026 15:11
@charliermarsh charliermarsh changed the base branch from charlie/elide-reachability-rank-metadata to main May 29, 2026 17:18
@charliermarsh charliermarsh force-pushed the charlie/consolidate-ast-id-map branch from 6d36bcd to 1d200ff Compare May 29, 2026 17:18
@charliermarsh charliermarsh changed the title [ty] View memory benchmarks [ty] Consolidate AST ID reverse lookup May 29, 2026
@charliermarsh charliermarsh added the performance Potential performance improvement label May 29, 2026
@charliermarsh charliermarsh marked this pull request as ready for review May 29, 2026 18:44
@charliermarsh charliermarsh marked this pull request as draft May 29, 2026 21:01
@charliermarsh charliermarsh force-pushed the charlie/consolidate-ast-id-map branch from 1d200ff to 401708c Compare May 29, 2026 21:26
Comment thread crates/ty_python_core/src/ast_ids.rs
@charliermarsh charliermarsh marked this pull request as ready for review May 30, 2026 11:26
Comment thread crates/ty_python_core/src/ast_ids.rs Outdated
}
}

uses_map.shrink_to_fit();

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.

Have you considered using a FrozenMap here?

use_id
}

pub(super) fn try_use_id(&self, key: impl Into<ExpressionNodeKey>) -> Option<ScopedUseId> {

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.

Did you review all call sites that this is indeed the uncommon case? Should we rename the method to try_find_use_id to make it more explicit that its complexity is O(n). Do you know what the perf impact of using a BTreeMap is? Should we change this in a separate PR to better understand the perf implications?

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.

Good call... Moving out...

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.

Not really convinced that either of these are worth it:

Comment thread crates/ty_python_core/src/ast_ids.rs Outdated
}
}

fn ast_ids<'db>(db: &'db dyn Db, scope: ScopeId) -> &'db AstIds {

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.

Should the api be changed to pass file instead?

@charliermarsh charliermarsh force-pushed the charlie/consolidate-ast-id-map branch from 6dc341d to 8c28fb0 Compare June 1, 2026 17:06
@charliermarsh charliermarsh merged commit bdf9f00 into main Jun 1, 2026
59 checks passed
@charliermarsh charliermarsh deleted the charlie/consolidate-ast-id-map branch June 1, 2026 19:46
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