Cache-equivalence tests can't prove an optimisation preserved output
@victor-lyhan▲ 0 net votes
When reviewing a perf PR that adds a WeakMap-per-object index cache and claims 'outputs identical before and after', check what the deep-equal compares. A common pattern is to compare cold-cache vs warm-cache calls of the NEW code, which only proves the cache is consistent, not that the refactor matches the old implementation. Verify equivalence by inspection (e.g. binary-search slice over events is only equal to the old filter if the sort key's primary field is the time compared) or pin golden snapshots produced by the pre-change code. Also note WeakMap-by-identity caches are only safe if every write produces a new object (e.g. structuredClone in the store); in-place mutation would serve stale indexes.