From 999add5f36a309b953b0b8e3cb705b5c535fee93 Mon Sep 17 00:00:00 2001 From: lcnr Date: Fri, 27 Sep 2024 19:28:09 +0200 Subject: [PATCH] completely outline `DelayedMap` cache accesses also increase the cutoff --- .../src/data_structures/delayed_map.rs | 41 ++++++++++++++++--- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/compiler/rustc_type_ir/src/data_structures/delayed_map.rs b/compiler/rustc_type_ir/src/data_structures/delayed_map.rs index 757a3849baf9..bccd50d3a0b8 100644 --- a/compiler/rustc_type_ir/src/data_structures/delayed_map.rs +++ b/compiler/rustc_type_ir/src/data_structures/delayed_map.rs @@ -2,7 +2,7 @@ use std::hash::Hash; use crate::data_structures::{HashMap, HashSet}; -const CACHE_CUTOFF: u32 = 16; +const CACHE_CUTOFF: u32 = 32; /// A hashmap which only starts hashing after ignoring the first few inputs. /// @@ -22,18 +22,35 @@ impl Default for DelayedMap { } impl DelayedMap { - #[inline] + #[inline(always)] pub fn insert(&mut self, key: K, value: V) -> bool { if self.count >= CACHE_CUTOFF { - self.cache.insert(key, value).is_none() + self.cold_insert(key, value) } else { self.count += 1; true } } - #[inline] + #[cold] + #[inline(never)] + fn cold_insert(&mut self, key: K, value: V) -> bool { + self.cache.insert(key, value).is_none() + } + + + #[inline(always)] pub fn get(&self, key: &K) -> Option<&V> { + if self.cache.is_empty() { + None + } else { + self.cold_get(key) + } + } + + #[cold] + #[inline(never)] + fn cold_get(&self, key: &K) -> Option<&V> { self.cache.get(key) } } @@ -51,18 +68,30 @@ impl Default for DelayedSet { } impl DelayedSet { - #[inline] + #[inline(always)] pub fn insert(&mut self, value: T) -> bool { if self.count >= CACHE_CUTOFF { - self.cache.insert(value) + self.cold_insert(value) } else { self.count += 1; true } } + #[cold] + #[inline(never)] + fn cold_insert(&mut self, value: T) -> bool { + self.cache.insert(value) + } + #[inline] pub fn contains(&self, value: &T) -> bool { + !self.cache.is_empty() && self.cold_contains(value) + } + + #[cold] + #[inline(never)] + fn cold_contains(&self, value: &T) -> bool { self.cache.contains(value) } }