Repository navigation
Conversation
_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]>
|
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. |
There was a problem hiding this comment.
Graphify review 
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
_rewire_unique_stub_nodesscanned every node and calledPath.resolve()for each Rustusepath it followed, so the pass costuseedges 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.rsnodes 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.graphify update .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 andGRAPH_REPORT.mdmatch v8 byte for byte.Limitations: parsing each declaring file in
_declared_external_modulesstill costs about 1.3s on rust-analyzer. On v8,use super::x::{self}in amod.rsdoes not resolve, and this PR leaves that unchanged.Test plan