Skip to content

Invalidating keys removes them from the disk order by key, not by walking it - #454

Merged
matrixarkai merged 3 commits into
mainfrom
perf/invalidation-leaves-the-disk-order-by-key
Nov 14, 2026
Merged

matrixarkai merged 3 commits into
mainfrom
perf/invalidation-leaves-the-disk-order-by-key

Conversation

@matrixarkai

Copy link
Copy Markdown
Owner

invalidate_keys_locked took the named keys out of the SSD order with retain, which visits every entry in the order. One invalidation therefore cost as much as the number of entries on disk, however few keys it named. Every other site that drops a disk entry already removes it by key, in constant time; this one now does too. What survives, and in what order, is unchanged.

Measured (one invalidate of a key, SSD-only cache, median of the best of 3 passes of 300; a debug build, so read the shape, not the microseconds):

entries on disk walk (main) by key (this)
1,000 112 us 138 us
4,000 359 us 154 us
16,000 1,392 us 137 us

The walk grows with the disk tier (about 12x for 16x the entries); the per-key removal is flat. At 1,000 entries the new code measures slightly slower, which is within the noise of a debug build; I did not chase it. In a TemporalStore shared-store harness profile this call was 75.9M instructions over 6,400 invalidations, but that corpus is small, so the table above is the evidence for the scaling.

Tests (src/tests/invalidate_disk_order.rs): the survivors and their order equal what a walk keeping every unnamed key would leave, at batch sizes 1, 2, 7, 8, 9 and 40 plus a key the cache never held, and the order and the index hold the same keys; a source guard pins that the batched path does not walk the order again (a behavioural test cannot see a walk that finds the right answer). Two planted defects are caught: the walk restored (caught by the guard) and only the first key removed (caught by the equivalence test).

Checks: cargo test --lib: 861 pass, 0 fail on this branch; 859 pass on main (the two extra are these tests).

🤖 Generated with Claude Code

…king it

`invalidate_keys_locked` took the named keys out of the SSD order with `retain`, which visits every
entry in the order. One invalidation therefore cost as much as the number of entries on disk, however
few keys it named, and a write into a cache with a large disk tier paid it per key. Every other site
that drops a disk entry already removes it by key, in constant time.

Each named key now leaves the order by its own handle. What survives, and in what order, is the same:
the new test keeps the walk as the oracle and compares at batch sizes either side of the eight the old
code switched to a set at, with keys the cache never held. The set switch is gone with the walk it
served. A source guard pins that the batched path does not walk the order again.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@matrixarkai
matrixarkai merged commit 5db2696 into main Nov 14, 2026
7 checks passed
matrixarkai added a commit that referenced this pull request Nov 14, 2026
…, not by walking it (#456)

Staging a batch for the SSD tier removed the batch's keys from the disk order with `retain`, which
visits every entry in the order, and then pushed them back at the end. One batch therefore cost as
much as the number of entries on disk, however few keys it staged. This is the same walk that
`invalidate_keys_locked` used to do before #454, on the write path.

Each staged key now leaves the order by its own handle and is pushed back as before, so the keys that
were not in the batch keep their places and the batch follows them in the order it was staged. The
batch's keys are unique (`staged_ssd_positions` collapses repeats), so this removes exactly what the
walk removed. The set switch at eight keys is gone with the walk it served.

Tests: the order after a batch is compared with the order the walk would have left, at batch sizes
either side of eight, for rewritten keys, and for a mix of rewritten and new keys; the test passes on
the old code as well as the new, which is what makes it an oracle. A source guard pins that the batch
path does not walk the order again.

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants