rust/compiler/rustc_codegen_ssa
Piotr Osiewicz 42e71bb8ea rustc_metadata: Preprocess search paths for better performance
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.
2024-11-15 10:35:33 +01:00
..
src rustc_metadata: Preprocess search paths for better performance 2024-11-15 10:35:33 +01:00
Cargo.toml Remove unused intercrate dependencies 2024-11-07 14:17:16 +00:00
messages.ftl Rollup merge of #131405 - davidtwco:hardcoded-strip-macos, r=jieyouxu,albertlarsan68 2024-11-05 23:43:56 +01:00
README.md

Please read the rustc-dev-guide chapter on Backend Agnostic Codegen.