Skip to content

Commit 4dbaa9d

Browse files
Rollup merge of #164150 - panstromek:pre-alloc-symbol-intern, r=nnethercote
Reserve more capacity for Symbol interner This avoids some resizing and rehashing. More details in the added comment.
2 parents 645a281 + bd198f3 commit 4dbaa9d

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

‎compiler/rustc_span/src/symbol.rs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2896,7 +2896,15 @@ impl Interner {
28962896
// `ByteSymbol`.
28972897
fn prefill(init: &[&'static str], extra: &[&'static str]) -> Self {
28982898
let values = init.iter().copied().chain(extra.iter().copied()).map(|str| str.as_bytes());
2899-
let (size_hint, _) = values.size_hint();
2899+
// At the time of writing, `helloworld` Check benchmark interns ~1k additional symbols.
2900+
// Some of the noisy ones (`include-blob`, `tt-muncher`, `externs`, `large-workspace`, etc.)
2901+
// are between 1k and 2k. Lowest number among non-artificial benchmarks is ~5k for `ucd`.
2902+
// This was chosen to make small, artificial benchmarks more stable, and to
2903+
// reduce resizing for normal code without regresing memory use for smaller crates.
2904+
// FIXME(panstromek): we could do better if we take into account whether this is
2905+
// Debug/Opt build. Those builds intern at least 6k more symbols than Check ones.
2906+
let additional_capacity = 2400;
2907+
let size_hint = values.size_hint().0 + additional_capacity;
29002908
let mut conflicting_values: Vec<&[u8]> = Vec::new();
29012909

29022910
let mut indices: HashTable<(&'static [u8], u32)> = HashTable::with_capacity(size_hint);

0 commit comments

Comments
 (0)