Repository navigation
feat: list keys in the order of their records in the segments - #11
Merged
Merged
Conversation
Reading every value of a 1.17 GB store in the order `keys` returned took 64 s, because the order was that of a hash map and most reads decoded a group again; in write order it takes 0.5 s. The README also tells callers to share one store per directory in a process: stores that write at the same time each leave a segment behind. Co-authored-by: WillBooster (Claude Code) <agent@willbooster.com>
Co-authored-by: WillBooster (Claude Code) <agent@willbooster.com>
Co-authored-by: WillBooster (Claude Code) <agent@willbooster.com>
Co-authored-by: WillBooster (Claude Code) <agent@willbooster.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Applying commitkv to the LLM response cache of an application (201,238 keys, 1.17 GB of values, 75 MB stored) showed two problems.
keys()returned the keys in the order of a hash map, so reading the values in that order decoded a 1 MiB group again for most of them: 64.5 s for the whole store. Nothing else lists the records, so a dump or a migration had no faster way.Requirements
docs/format.md).keys()returns the keys in the order of their current records in the segments instead of adding an iteration API, because the existing API then reads a whole store fast and the order was unspecified before.refresh) and the tests that stand in for separate checkouts depend on that independence.Customer Summary
keys()lists the keys in the order their current values lie in the segments, oldest segment first, in Rust, Python, Node.js, and Bun. This is the order one store wrote them; the order across several stores does not tell which write came first. Reading every value in that order took 0.5 s on the store above instead of 64.5 s.Technical Summary
Store::keyssorts the index by the position that already decides which record of a key is current (segment name, then end offset);State::positionnow holds that ordering for both uses. The segment format and the files a store writes are unchanged.Testing
cargo test --release --manifest-path rust/Cargo.toml(addskeys_are_listed_in_the_order_a_store_wrote_their_current_values, which covers several segments and a replaced key),cargo clippy,cargo fmt --checkbun run verify,bun wb testkeys()order 64.5 s → 0.48 s; 2,000 values in random order unchanged at about 0.65 s.