Add Eytzinger layout option for key digests - #33
Merged
Conversation
Base automatically changed from
claude/readonly-db-optimization-19c03f
to
main
August 16, 2026 05:34
hadashiA
force-pushed
the
claude/eytzinger-digests
branch
from
August 16, 2026 05:39
2af2454 to
02ca03d
Compare
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.
Note
Rebased onto
main(#31 and #32 are both merged). The readers now carry three digest search paths: Eytzinger descent (this PR, per-page flag) → SIMD hybrid lower bound from #32 (sorted digests) → classic mixed binary search (netstandard / non-SIMD fallback).Summary
Adds
DatabaseBuilder.EytzingerDigests(default off): each node's key digest array is stored as a complete binary tree in Eytzinger (BFS) order, padded withulong.MaxValueto 2^k - 1 slots, instead of sorted order. The digest search becomes a fully branch-free descent —— with the top levels of the tree clustered in the first cache line. The rank is then resolved to an entry through the run of equal digests with full key comparisons (entry metadata and keys stay in sorted order; only the digest array is permuted).
Format notes:
NodeFlags.EytzingerDigests(bit 9); files using it are marked 1.2. Older readers cannot parse such pages. Files built without the option are byte-identical to before.Benchmark — a workload-dependent trade
M4 / .NET 10, ShortRun.
RandomKeysrepeats the same 1000-key sequence every op (the branch predictor memorizes it);RandomKeys_NoRepeat(added in #32) never repeats — the realistic model of random access.The mechanism cuts both ways: the descent has no mispredictable branches (halves the cost when the predictor is useless) but its loads form a serial dependency chain (a correctly-predicted binary search speculates loads ahead and wins when the access pattern is learnable). Hence opt-in, default off: workloads dominated by unpredictable point lookups can halve them; predictable/looping access should keep the sorted layout.
Tests: 85/85 pass after the rebase (including #32's
KeyDigestSearchTestagainst the merged readers), with newEytzingerDigestsTestcoverage for padded-tree boundaries (1..8 entries), digest-collision runs, range/count bounds, non-unique secondary indexes, and iterators.🤖 Generated with Claude Code