Add Eytzinger layout option for key digests - #33
Open
hadashiA wants to merge 1 commit into
Open
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.
Note
Stacked on #31 (struct key comparer specialization) — review the last commit only. Retarget to
mainafter #31 merges. Independent of #32 (the two changes optimize the same search from different directions and can land in either order; whichever goes second needs a small conflict resolution in the readers).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: 81/81 pass, including new
EytzingerDigestsTestcoverage for padded-tree boundaries (1..8 entries), digest-collision runs, range/count bounds, non-unique secondary indexes, and iterators.🤖 Generated with Claude Code