From 27a8a62ade485cf8375d51767c0e3e2e606d4ac4 Mon Sep 17 00:00:00 2001 From: "Dylan M. Taylor" Date: Wed, 4 Nov 2026 03:34:51 +0000 Subject: [PATCH] address review: drop only the excess sim checkpoints when trimming --- crates/effects/src/util.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/crates/effects/src/util.rs b/crates/effects/src/util.rs index 9fee76b64..5f7fb5d66 100644 --- a/crates/effects/src/util.rs +++ b/crates/effects/src/util.rs @@ -636,13 +636,13 @@ impl SimCache { if e.checkpoints.len() > MAX_SIM_CHECKPOINTS { e.checkpoints.retain(|(s, _)| s % SIM_CHECKPOINT == 0 && *s != target); e.checkpoints.sort_by_key(|(s, _)| *s); - while e.checkpoints.len() + 1 > MAX_SIM_CHECKPOINTS { - let mut k = 0; - e.checkpoints.retain(|_| { - k += 1; - k % 2 == 1 - }); - } + // Drop only the excess, evenly spaced, so the rest keep their seek distance. + let (len, excess) = (e.checkpoints.len(), (e.checkpoints.len() + 1).saturating_sub(MAX_SIM_CHECKPOINTS)); + let mut i = 0; + e.checkpoints.retain(|_| { + i += 1; + (i * excess) / len == ((i - 1) * excess) / len + }); e.checkpoints.push((target, out.clone())); } out @@ -855,6 +855,9 @@ mod tests { steps.set(0); assert_eq!(*c.run(1, target, || 0, count), target); assert_eq!(steps.get(), 0, "the second request is answered from the cache"); + // Only the excess is dropped: the other aligned checkpoints stay. + let kept = c.inner.lock().map(|g| g[0].checkpoints.len()).unwrap_or(0); + assert_eq!(kept, MAX_SIM_CHECKPOINTS, "trimmed to the cap, not halved"); } #[test]