Skip to content

Commit 1368f04

Browse files
authored
fix(EXC): Make expensive debug assert conditional (#2820)
This fix accelerates tests with many unique queries.
1 parent a31f1db commit 1368f04

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

rs/utils/lru_cache/src/lib.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,18 @@ where
138138
}
139139

140140
fn check_invariants(&self) {
141-
debug_assert_eq!(
142-
self.size,
143-
self.cache
144-
.iter()
145-
.map(|(key, value)| key.count_bytes() + value.count_bytes())
146-
.sum::<usize>()
147-
);
141+
// Iterating over random memory locations is expensive and slows down some tests,
142+
// so the debug assert is limited to 1k cache entries.
143+
#[cfg(debug_assertions)]
144+
if self.len() < 1_000 {
145+
debug_assert_eq!(
146+
self.size,
147+
self.cache
148+
.iter()
149+
.map(|(key, value)| key.count_bytes() + value.count_bytes())
150+
.sum::<usize>()
151+
);
152+
}
148153
debug_assert!(self.size <= self.capacity);
149154
}
150155
}

0 commit comments

Comments
 (0)