Skip to content

perf(extract): index Rust module lookups in the stub rewire - #5668

Open
Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/rust-stub-rewire-index
Open

Max17190 wants to merge 1 commit into
Graphify-Labs:v8from
Max17190:perf/rust-stub-rewire-index

Conversation

@Max17190

@Max17190 Max17190 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Why

_rewire_unique_stub_nodes scanned every node and called Path.resolve() for each Rust use path it followed, so the pass cost use edges times graph nodes. A cold build of rust-analyzer took 31 minutes. Fixes #5665.

Summary

The pass now builds its lookups once: resolved paths, Rust files by module name, nodes by resolved path, and lib.rs nodes by crate. Nodes do not change until the end of the pass, so the indexes cannot go stale. Lookups return nodes in the original order.

Cold graphify update . v8 This PR
rust-analyzer 1890s 29.9s
tauri 118s 12.6s

Each number is the median of 3 runs on a 16 vCPU Linux machine with CPython 3.12, except rust-analyzer on v8, which ran once. graph.json, the partition cache and GRAPH_REPORT.md match v8 byte for byte.

Limitations: parsing each declaring file in _declared_external_modules still costs about 1.3s on rust-analyzer. On v8, use super::x::{self} in a mod.rs does not resolve, and this PR leaves that unchanged.

Test plan

python -m pytest tests -q -n 8 --dist loadfile   # 12639 passed
python -m pytest tests/test_rust_use_module_lookup_cost.py -q   # 2 passed; both fail on v8
uv run ruff check .                              # passes
uv run pyright --pythonpath .venv/bin/python     # same diagnostics as v8
uv run python -m tools.skillgen --check          # 134 artifacts match
graphify update .   # cold on rust-analyzer, tauri and VS Code, and incremental on tauri; identical to v8
  • Read CONTRIBUTING.md
  • AI help disclosed in the commit trailer

_rewire_unique_stub_nodes follows every Rust `use crate::`, `super::`,
`self::` and workspace-crate module path to the file it names. Each
lookup scanned the whole node list and resolved node paths with
Path.resolve(), and `_lib_file_for_crate` re-ran crate_of over every
node per edge, so the pass cost Rust use edges x graph nodes filesystem
calls. On a cold build of rust-analyzer this pass took almost the entire
run.

Build the lookups once per pass instead, lazily and in original node
order:

- resolved source paths memoized by their source_file string
- Rust file nodes bucketed by the module name they declare
- every node keyed by resolved source path, for whole-file matches
- lib.rs nodes per crate, one entry per node so duplicates stay
  ambiguous
- crate_of answers per source_file, and resolved declaring-file paths

Nodes are not mutated until `nodes[:]` at the end of the pass, so the
indexes cannot go stale. Results keep the original node order, no path
is resolved that the old scans would not, and a resolve() that raises is
never memoized. Graph output is unchanged.

Fixes Graphify-Labs#5665

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Max17190
Max17190 requested a review from safishamsi as a code owner December 1, 2026 04:45
@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Dec 1, 2026
@github-actions

github-actions Bot commented Dec 1, 2026

Copy link
Copy Markdown

Thanks for the pull request, @Max17190. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify review View in Graphify

Looks safe to merge · Merge confidence 5/5

No issues reported · High impact

The Rust module rewiring pass now caches resolved source paths and crate lookups, and builds node indexes for repeated module and whole-file searches.

Code graph · 5315 functions depend on this change
  • 389 of 666 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed f341ebb

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rust module path lookups rescan every node per use edge, so cold Rust builds take tens of minutes

1 participant