Corgi reduce: one id scheme, bounded windows - #897
Merged
Merged
Conversation
Rework the corgi reduce backend around one way of naming values, and present the key space in bounded windows. Ids: - A key's id is its arrangement identifier, as before. - A value's id names a row: `(column, row)` in a pool of the chunks' own value columns and the output columns the backend builds. - Input: each key's rows are sorted by value with corgi's `sort_blocks`, and each run of equal values is one id. - Output: each key's desired values are netted against its current output by comparing values (`compare_at`); a value not seen before gets a new id. This removes `IdPool`, `IdHasher`, `ids()`, `merge_present`, the separate presentation paths, and the `HashMap` in `reduce_corrections`. Values are no longer hashed anywhere in the backend. Windows: a retire's keys are searched once, then presented a few at a time, each window holding about `window_size` input records (default `1 << 12`, as `VecReduceBackend` uses). A key is never split across windows. Non-test lines of reduce.rs: 722 -> 551. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Supersedes #895 and #896.
Reworks the corgi reduce backend around one way of naming values, and presents the key space in bounded windows.
reduce.rsgoes from 722 to 551 non-test lines.Ids
(column, row)in a pool of the chunks' own value columns and the output columns the backend builds.sort_blocks; each run of equal values is one id.compare_at); a value not seen before gets a new id.Removed:
IdPool,IdHasher,ids(),merge_present, the separate presentation paths, and theHashMapinreduce_corrections. Values are no longer hashed anywhere in the backend.Windows: a retire's keys are searched once, then presented a few at a time, each window holding about
window_sizeinput records (default1 << 12, asVecReduceBackenduses). A key is never split across windows.Measurements (same-plan harness, 1 worker, median of 3; master-next -> this):
Peak RSS, 4M-row loads: count 1145 -> 646 MiB, count2 1397 -> 770 MiB, distinct 1145 -> 646 MiB; reach 640 -> 663 MiB.
min, reach, and scc are 2-4% slower. The cost is the input sort: chunks are already sorted by value, and this sorts again rather than merging those runs. A
sort_blocksthat uses presorted runs would recover it inside corgi, leaving this file as is.Validation: outputs match compiled DD for count, count2, distinct, min, min2, reach, scc at 1 and 4 workers; AoC 33/33 on corgi; workspace tests pass; interactive and server suites pass with a one-record window.
Comments removed with their code:
IdHasher's profiling note, theids()andmerge_presentdocs, and "Both sides ascend, so this is a merge" (key lists are now extend, sort, dedup). The module doc's ids and transcode paragraphs are rewritten for the new scheme, and Min's "reuses its input value id" no longer applies.🤖 Generated with Claude Code