Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit e87dee8

Browse files
committed
completely outline DelayedMap cache accesses
also increase the cutoff
1 parent f550e0f commit e87dee8

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

compiler/rustc_type_ir/src/data_structures/delayed_map.rs

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::hash::Hash;
22

33
use crate::data_structures::{HashMap, HashSet};
44

5-
const CACHE_CUTOFF: u32 = 16;
5+
const CACHE_CUTOFF: u32 = 32;
66

77
/// A hashmap which only starts hashing after ignoring the first few inputs.
88
///
@@ -22,18 +22,35 @@ impl<K, V> Default for DelayedMap<K, V> {
2222
}
2323

2424
impl<K: Hash + Eq, V> DelayedMap<K, V> {
25-
#[inline]
25+
#[inline(always)]
2626
pub fn insert(&mut self, key: K, value: V) -> bool {
2727
if self.count >= CACHE_CUTOFF {
28-
self.cache.insert(key, value).is_none()
28+
self.cold_insert(key, value)
2929
} else {
3030
self.count += 1;
3131
true
3232
}
3333
}
3434

35-
#[inline]
35+
#[cold]
36+
#[inline(never)]
37+
fn cold_insert(&mut self, key: K, value: V) -> bool {
38+
self.cache.insert(key, value).is_none()
39+
}
40+
41+
42+
#[inline(always)]
3643
pub fn get(&self, key: &K) -> Option<&V> {
44+
if self.cache.is_empty() {
45+
None
46+
} else {
47+
self.cold_get(key)
48+
}
49+
}
50+
51+
#[cold]
52+
#[inline(never)]
53+
fn cold_get(&self, key: &K) -> Option<&V> {
3754
self.cache.get(key)
3855
}
3956
}
@@ -51,18 +68,30 @@ impl<T> Default for DelayedSet<T> {
5168
}
5269

5370
impl<T: Hash + Eq> DelayedSet<T> {
54-
#[inline]
71+
#[inline(always)]
5572
pub fn insert(&mut self, value: T) -> bool {
5673
if self.count >= CACHE_CUTOFF {
57-
self.cache.insert(value)
74+
self.cold_insert(value)
5875
} else {
5976
self.count += 1;
6077
true
6178
}
6279
}
6380

64-
#[inline]
81+
#[cold]
82+
#[inline(never)]
83+
fn cold_insert(&mut self, value: T) -> bool {
84+
self.cache.insert(value)
85+
}
86+
87+
#[inline(always)]
6588
pub fn contains(&self, value: &T) -> bool {
89+
!self.cache.is_empty() && self.cold_contains(value)
90+
}
91+
92+
#[cold]
93+
#[inline(never)]
94+
fn cold_contains(&self, value: &T) -> bool {
6695
self.cache.contains(value)
6796
}
6897
}

0 commit comments

Comments
 (0)