Add key digest arrays to BTree nodes (format 1.1) - #30
Merged
Conversation
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.
Summary
B+Tree nodes now carry a contiguous array of 8-byte order-preserving key digests, and searches probe that array instead of dereferencing the variable-length keys scattered across the page. One cache line covers eight probes, and the per-probe two-step dependent load (meta → key) collapses to a single load.
(1 op = 1000 queries. The 1M cases are DRAM-latency bound, where fewer touched lines and a ~20% larger page count cancel out; the win is in the CPU/cache-bound regime.)
Digest definitions
IKeyEncodinggainsSupportsKeyDigest/GetKeyDigest(default interface members, so custom encodings are unaffected):Guid.CompareTois not byte-lexicographic); their trees keep the plain layout automatically.Format & compatibility
[PageHeader][NodeHeader][digest u64 × N][meta × N][payload].NodeFlags.HasKeyDigests), per page — digest and plain trees coexist in one file, and 1.0 files remain fully readable.DatabaseBuilder.KeyDigests(defaulttrue) — disable to produce byte-identical 1.0 output (header stays MinorVersion 0) at the cost of the search speedup. File-size cost when enabled: +8 bytes/entry (~+27% for this benchmark's 13-byte values; proportionally less for larger values).Also
Search/SearchAsyncwith LowerBound/UpperBound returned not-found when the bound was the first entry of the next leaf; they now continue to the right sibling. The new page layout shifted leaf boundaries and exposed this in existing range tests.BigReadBenchmark(1M rows, ~40 MB) covering the DRAM-bound regime.KeyDigests = falselayout.All 75 tests pass.
🤖 Generated with Claude Code