-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rustc_metadata: Preprocess search paths for better performance #132910
Conversation
This comment has been minimized.
This comment has been minimized.
I am pretty sure this should get the attention of r? @saethlin |
In 081797d I've additionally started filtering out entries that cannot match any query; basically, given a target spec we can remove entries from the map before any query takes place. |
Exactly how did you come up with this figure? I've cloned Zed and I'm looking through profiles of builds of the repo and while I certainly can see an impressive amount of time is being spent in this code, I don't think I can come up with an entire 6%. So I'm wondering if I just don't understand how to interact with this repo or if there's some particular workflow I should be investigating. |
@saethlin this figure is an end-to-end timing of I did not really mean for this figure to stand as an argument for merging this; it's just that I'm aware that 100ms (or whatever the figure is, depending on a package being built) might not seem like much, but it does add up in the long run for us. |
I think you are underestimating how much we care about compiler performance. In general, a 6% win is quite significant. I don't think I've seen any of the pathology you've identified via Zed in any of our existing benchmark suite. I just checked (what I think is our go-to "big crate"?) cargo-0.60.0 Debug IncrUnchanged (touch a file and run But with just the two style nits, I think this PR is good to go. I'm very happy to see people identify a problem with the compiler and try to fix it :) |
This comment has been minimized.
This comment has been minimized.
@bors r+ rollup=never |
maybe cleanup the commit history? |
Over in Zed we've noticed that loading crates for a large-ish workspace can take almost 200ms. We've pinned it down to how rustc searches for paths, as it performs a linear search over the list of candidate paths. In our case the candidate list had about 20k entries which we had to iterate over for each dependency being loaded. This commit introduces a simple FilesIndex that's just a sorted Vec under the hood. Since crates are looked up by both prefix and suffix, we perform a range search on said Vec (which constraints the search space based on prefix) and follow up with a linear scan of entries with matching suffixes. FilesIndex is also pre-filtered before any queries are performed using available target information; query prefixes/sufixes are based on the target we are compiling for, so we can remove entries that can never match up front. Overall, this commit brings down build time for us in dev scenarios by about 6%. 100ms might not seem like much, but this is a constant cost that each of our workspace crates has to pay, even when said crate is miniscule.
b07313a
to
42e71bb
Compare
@bors r=saethlin |
☀️ Test successful - checks-actions |
Finished benchmarking commit (76fd471): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countThis is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.
Max RSS (memory usage)Results (primary -3.0%, secondary 2.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResults (primary 2.3%, secondary 2.7%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 788.822s -> 786.926s (-0.24%) |
@rustbot label: +perf-regression-triaged The reported regressions are extremely marginal, and the discussion above: #132910 (comment) contains instructions for how to demonstrate a quite significant benefit of this change. |
Over in Zed we've noticed that loading crates for a large-ish workspace (~100 members of workspace, over 1000 crates being built for the main binary target) can take almost 200ms. We've pinned it down to how rustc searches for paths to dependency files, as it performs a linear search over the list of candidate paths. In our case the candidate list had about 20k entries which we had to iterate over for each dependency being loaded. Our workspace is also pretty bottom-heavy, e.g. most of the workspace members pull in most of the transitive dependencies one way or another, which means that we spend quite some time loading crates at rustc startup.
This commit introduces a simple FilesIndex that's just a BTreeMap under the hood. Since crates are looked up by both prefix and suffix, we perform a range search on said BTree (which constraints the search space based on prefix) and follow up with a linear scan of entries with matching suffixes.
Overall, this commit brings down build time for us in dev scenarios by about 6%. 100ms might not seem like much, but this is a constant cost that each of our workspace crates has to pay, even when said crate is miniscule.