about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2025-02-26 13:01:45 +0000
committerbors <bors@rust-lang.org>2025-02-26 13:01:45 +0000
commitac91805f3179fc2225c60e8ccf5a1daa09d43f3d (patch)
tree3c84a9c84cebe59e0608228516706aaee9720f8c /compiler/rustc_data_structures/src
parent2af87eab3b4890d62ad998cf9c55e076d91bf06a (diff)
parent7d2cfcab9d8291e412f41e43cdadf587d700d577 (diff)
downloadrust-ac91805f3179fc2225c60e8ccf5a1daa09d43f3d.tar.gz
rust-ac91805f3179fc2225c60e8ccf5a1daa09d43f3d.zip
Auto merge of #137354 - FractalFir:intern_with_cap, r=FractalFir
Change interners to start preallocated with an increased capacity

Inspired by https://github.com/rust-lang/rust/issues/137005.

Added a `with_capacity` function to `InternedSet`. Changed the `CtxtInterners` to start with `InternedSets` preallocated with a capacity.

This *does* increase memory usage at very slightly(by ~1 MB at the start), altough that increase quickly disaperars for larger crates(since they require such capacity anyway).

A local perf run indicates this improves compiletimes for small crates(like `ripgrep`), without a negative effect on larger ones.
Diffstat (limited to 'compiler/rustc_data_structures/src')
-rw-r--r--compiler/rustc_data_structures/src/sharded.rs3
1 files changed, 3 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/sharded.rs b/compiler/rustc_data_structures/src/sharded.rs
index 65488c73d3c..5a53f8af5f8 100644
--- a/compiler/rustc_data_structures/src/sharded.rs
+++ b/compiler/rustc_data_structures/src/sharded.rs
@@ -143,6 +143,9 @@ pub fn shards() -> usize {
 pub type ShardedHashMap<K, V> = Sharded<FxHashMap<K, V>>;
 
 impl<K: Eq, V> ShardedHashMap<K, V> {
+    pub fn with_capacity(cap: usize) -> Self {
+        Self::new(|| FxHashMap::with_capacity_and_hasher(cap, rustc_hash::FxBuildHasher::default()))
+    }
     pub fn len(&self) -> usize {
         self.lock_shards().map(|shard| shard.len()).sum()
     }