Skip to content

Commit 0fd98fe

Browse files
committed
Auto merge of rust-lang#137563 - FractalFir:dep_graph_cap, r=<try>
[Perf experiment] Changed TaskDeps to start with preallocated with 1024 capacity This is a tiny change that makes `TaskDeps::read_set` start preallocated with capacity for 1024 elements(4096 bytes). Somewhat annoyingly, `HashSet::with_capacity` requires the hasher to implement `RandomState`. Since `FxHash` does not implement `RandomState`, I had to use `HashSet::with_capacity_and_hasher`, which required re-exporting `FxBuildHasher` in `rustc_data_structures`. From local profiling, it looks like `TaskDeps::read_set` is one of the most-often resized hash-sets in `rustc`. Local perf runs indicate this is a small perf improvement(without any regressions). There is also no significant RSS increase(the RSS changes are noisy and cancel themselves out almost entirely). Still, since the local and CI results can differ, I'll do a CI perf run before this PR can be reviewed. `@bors` try `@rust-timer` queue
2 parents 617aad8 + 02aa397 commit 0fd98fe

File tree

2 files changed

+3
-3
lines changed
  • compiler
    • rustc_data_structures/src
    • rustc_query_system/src/dep_graph

2 files changed

+3
-3
lines changed

compiler/rustc_data_structures/src/fx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::hash::BuildHasherDefault;
22

3-
pub use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
3+
pub use rustc_hash::{FxBuildHasher, FxHashMap, FxHashSet, FxHasher};
44

55
pub type StdEntry<'a, K, V> = std::collections::hash_map::Entry<'a, K, V>;
66

compiler/rustc_query_system/src/dep_graph/graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::sync::Arc;
77
use std::sync::atomic::{AtomicU32, Ordering};
88

99
use rustc_data_structures::fingerprint::Fingerprint;
10-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
10+
use rustc_data_structures::fx::{FxBuildHasher, FxHashMap, FxHashSet};
1111
use rustc_data_structures::profiling::{QueryInvocationId, SelfProfilerRef};
1212
use rustc_data_structures::sharded::{self, Sharded};
1313
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -1299,7 +1299,7 @@ impl Default for TaskDeps {
12991299
#[cfg(debug_assertions)]
13001300
node: None,
13011301
reads: EdgesVec::new(),
1302-
read_set: FxHashSet::default(),
1302+
read_set: FxHashSet::with_capacity_and_hasher(1024, FxBuildHasher::default()),
13031303
phantom_data: PhantomData,
13041304
}
13051305
}

0 commit comments

Comments
 (0)