Skip per-entry range checks for leaves fully inside an extract range#1289
Closed
cberner wants to merge 1 commit into
Closed
Skip per-entry range checks for leaves fully inside an extract range#1289cberner wants to merge 1 commit into
cberner wants to merge 1 commit into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1289 +/- ##
==========================================
- Coverage 90.16% 90.15% -0.02%
==========================================
Files 36 36
Lines 16161 16212 +51
==========================================
+ Hits 14572 14616 +44
- Misses 1589 1596 +7
🚀 New features to boost your workflow:
|
9b84014 to
a811708
Compare
Each entry visited by extract_from_if settled its cursor end individually: re-activating the live cursor, re-reading the entry, and comparing its key against the other end's bound, even though every key in a leaf that lies entirely inside the range passes the same checks. When an entry settles, compare the leaf's furthest key against the opposite bound once and remember how many entries ahead of the gap share the verdict; their settles then skip the cursor work entirely. Only advancing the gap by one entry may consume from this run, and every other reposition (leaf flushes, parking the end, errors) clears it, so the fast path never outlives the position it was computed for. The final leaf at the range boundary keeps the per-entry comparison. On the lmdb_benchmark extract_if phase (5M entries) with the file in memory, the scan drops from about 225ms to 180ms; commit time is unchanged. Assisted-by: Claude Code https://claude.ai/code/session_019fyYXygUxss6KcMo5jmBnw
cc33268 to
94b3e2b
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.
Summary
First of a series of PRs splitting the extract_if/retain optimizations into individually reviewable pieces, ordered by expected impact on fast storage (NVMe), where the remaining ~2x gap vs lmdb is CPU-bound rather than fsync-bound.
Each entry visited by
extract_from_ifsettled its cursor end individually: re-activating the live cursor, re-reading the entry, and comparing its key against the other end's bound — even though every key in a leaf that lies entirely inside the range passes the same checks. This was the largest single CPU cost in the scan.Now, when an entry settles, the leaf's furthest key is compared against the opposite bound once, and the number of entries ahead of the gap that share the verdict is remembered; their settles skip the cursor work entirely. Only advancing the gap by one entry may consume from this run; every other reposition (leaf flushes, parking the end, errors) clears it. The final leaf at the range boundary keeps the per-entry comparison.
Benchmark (lmdb_benchmark extract_if phase, 5M entries, file in memory to isolate CPU)
Planned follow-up PRs (one at a time, in this order)
Testing
just testgreen (deny, fmt, clippy, full suite)fuzz_redb52k iterations, no findings🤖 Generated with Claude Code
https://claude.ai/code/session_019fyYXygUxss6KcMo5jmBnw