Skip to content

prompt cache: Imprint finds records by key through an index (stacked on #2316) - #2351

Merged
ashhart merged 3 commits into
mainfrom
lead/imprint-keys
Nov 9, 2026
Merged

ashhart merged 3 commits into
mainfrom
lead/imprint-keys

Conversation

@ashhart

@ashhart ashhart commented Nov 6, 2026 •

Copy link
Copy Markdown
Owner

Rebased onto main now that #2316 has landed: these are the two commits.

--learn's Imprint looked records up by key with a linear scan: find, has, touch, and reload's per-record find after another writer appends. This keeps an index from each record's key to its place in the record list, updated wherever the list changes:

  • add appends;
  • remove renumbers the records after the one it took out;
  • reload swaps in the fresh map;
  • open's duplicate check uses the same map.

The records, their order, the clock and eviction victims are the same as before.

Timing at 100,000 learned states (Apple M3 Ultra, ReleaseFast, median of 5 fresh processes; the new timing step is test-startup-states-timing):

Call Before After
find, has and touch 24-57 µs 0.02-0.04 µs
reload's finds after another writer appended 2.8 s 1.1 ms
an add that has to reload 3.6 s 0.81-0.86 s (the index re-read)

What this doesn't change: a request's lookup is still about 0.7 ms warm and 1.7 ms cold at 100K. That's best, a prefix scan over every record, which a key index can't speed up. remove's index rewrite is I/O. At 1,000 records every call was already under 17 µs, so the gain shows at large stores.

Checks:

  • Two new host tests (prompt_imprint_keys_test.zig) check records, order, clock and victims against a model built from the old linear scans, over random sequences of adds, touches, removes, evictions and reloads. They also pass on the old code, and five planted faults each make them fail.
  • The prompt_imprint.zig tests pass 17/17, and zig build test-learn-recovery passes 528/528.
  • zig fmt --check passes.

@ashhart
ashhart merged commit 4d0339b into main Nov 9, 2026
4 of 10 checks passed
ashhart added a commit that referenced this pull request Nov 10, 2026
Figures corrected to the PRs' measured ones (#2699 head runs, #2509,
#2633, #2436, #2644, #2593, #2430, #2568), scope fixed (#2253, #2287,
#2511, #2569, #2337, #2627, #2351, #2626), unsourced figures dropped
(#2181, #2606, #2257's pricing clauses), the shipped #2176, #2565,
#2548 and gfx12 silu entries and the first #2625 copy removed, and
the #2568 and #2352 entries unwrapped to one line each.
@ashhart
ashhart deleted the lead/imprint-keys branch November 10, 2026 16:34
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.

1 participant