Corgi: search few keys in a long chunk in lockstep - #900
Merged
frankmcsherry merged 1 commit intoSep 23, 2026
Merged
frankmcsherry merged 1 commit into
frankmcsherry merged 1 commit into
Conversation
Reduce presentation and the join's probe side find each key's rows in every chunk with `MatchingRanges`, which gallops from the previous match. Each search then depends on the last, and in an incremental round (tens of keys against a chunk of 10^5 rows) each lands on a cold line, so the misses are paid one after another. In SCC that loop was ~13% of churn time. Fewer probes did not help: interpolating the start halved them and saved 4%. `matching_ranges` searches the keys in lockstep instead: branch-free binary searches that advance one level at a time together, so each level issues one independent load per key and the misses overlap. It keeps the merge when the keys are dense relative to the chunk (4 x keys x log2(rows) > rows + keys), where sequential steps are cheaper. Corgi, 1 worker, 5 interleaved runs, medians (before -> after): scc 200k edges, 200 x 50 churn 4.49 -> 4.06 s reach 2M edges, 100 x 100 churn 691 -> 480 ms kcore 200k edges, 200 x 50 churn 836 -> 829 ms (noise) count 1M rows, 200 x 500 churn 2.27 -> 2.29 s Loads within 1.5%. Outputs match; interactive tests pass; AoC 2023 corgi 33/33. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
frankmcsherry
marked this pull request as ready for review
September 23, 2026 11:55
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.
Reduce presentation and the join's probe side find each key's rows in every chunk with
MatchingRanges, which gallops from the previous match. Each search then depends on the last, and in an incremental round (tens of keys against a chunk of 10^5 rows) each lands on a cold line, so the misses are paid one after another. In SCC that loop was ~13% of churn time. Fewer probes did not help: interpolating the start halved them and saved 4%.matching_rangessearches the keys in lockstep instead: branch-free binary searches that advance one level at a time together, so each level issues one independent load per key and the misses overlap. It keeps the merge when the keys are dense relative to the chunk (4 x keys x log2(rows) > rows + keys), where sequential steps are cheaper.Corgi, 1 worker, 5 interleaved runs, medians (before -> after):
scc 200k edges, 200 x 50 churn 4.49 -> 4.06 s
reach 2M edges, 100 x 100 churn 691 -> 480 ms
kcore 200k edges, 200 x 50 churn 836 -> 829 ms (noise)
count 1M rows, 200 x 500 churn 2.27 -> 2.29 s
Loads within 1.5%. Outputs match; interactive tests pass; AoC 2023 corgi 33/33.