-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rust_analyzer: don't build a tree of RustAnalyzerInfos (#3028)
This patch adds an `id` to RustAnalyzerInfo, and replace all the recursive RustAnalyzerInfos with the respective crate `id`s. This fixes RustAnalyzerInfos becoming exponentially expensive to build in the presence of aliases. --- Before this patch, `RustAnalyzerInfo.deps` contains the RustAnalyzerInfo of the target crate's deps, and so on recursively. This forms a graph of Infos where there is one Info per target, but multiple paths from one target to another. e.g. these could all point to `bar`: `foo.deps[0] == foo.deps[1].deps[0] == foo.aliases[0]`. If we walk `foo` as a tree, we will see `bar` multiple times. Two operations that do this are `print(info)` and `{info: 42}` which hashes the object. As the graph grows, the number of paths grows combinatorically. `RustAnalyzerInfo.aliases` is defined as a dict from `RustAnalyzerInfo => string`, so building this triggers the slowdown. It would be possible to fix this by e.g. replacing this dict with a list of pairs. However the work `rust_analyzer_aspect` does is fundamentally local and does not need a recursive data structure. Eliminating it means we can freely use these values as keys, print them, etc. --- Timings for `ra_ap_rust-analyzer` (which heavily aliases its deps): ``` blaze build //third_party/bazel_rules/rules_rust/tools/rust_analyzer:gen_rust_project; \ time blaze run //third_party/bazel_rules/rules_rust/tools/rust_analyzer:gen_rust_project -- //third_party/rust/ra_ap_rust_analyzer/... ===Before=== Executed in 211.06 secs fish external usr time 0.24 secs 0.00 micros 0.24 secs sys time 1.24 secs 604.00 micros 1.24 sec ===After=== Executed in 3.24 secs fish external usr time 0.15 secs 389.00 micros 0.15 secs sys time 1.18 secs 125.00 micros 1.18 secs ```
- Loading branch information
1 parent
6cfd508
commit 443b089
Showing
3 changed files
with
45 additions
and
46 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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