rust/compiler/rustc_session
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 compiler: Add rustc_abi dependence to the compiler 2024-10-27 21:10:58 -07:00
messages.ftl rust_for_linux: -Zregparm=<N> commandline flag for X86 (#116972) 2024-10-18 00:29:31 +07:00