Repository navigation
perf(python): stream unfiltered batch sampler ranges - #11744
Merged
Xuanwo merged 1 commit intoDec 2, 2026
Merged
Conversation
Problem ShardedBatchSampler allocates every range assigned to the rank before returning the first unfiltered batch. Solution Keep sequential batch starts in a range and construct each pair of bounds as the native reader consumes it. Shuffle only the starts when requested. Result Reading a prefix no longer visits every sequential range. Seeded order and partial batches are preserved after deletions.
Contributor
There was a problem hiding this comment.
✅ Gate recommendation: approve.
No blocking findings. Local tests confirmed on-demand range consumption and preserved seeded order across deletions and a partial batch. A same-reader comparison reduced sequential first-batch peak Python allocation from about 16 MiB to 2.5 KiB, with small full-shard timing differences.
Xuanwo
approved these changes
Dec 2, 2026
Collaborator
Author
|
@Xuanwo Thanks! |
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.
Problem
Unfiltered batch sharding builds the whole rank's list of row ranges before returning a reader. This makes even a single-batch read allocate in proportion to the shard size.
Solution
Generate each range when the native reader asks for it. Randomized sharding keeps a shuffled list of start offsets and computes the corresponding ends on demand.
Result
On two fragments totaling 4,194,307 rows, first-batch peak traced Python allocation fell from about 16 MiB to under 4 KiB for sequential reads (two ranks, 16 rows per batch, readahead 4). The sampler suite passed all 135 tests, including seeded order across deletions and a partial final batch.
In a separate full-shard check, both implementations used the same optimized native reader at
38040f844. With 262,147 source rows and 256-row batches, median elapsed time over 48 runs went from 49.2 to 49.9 ms sequentially and from 49.4 to 50.4 ms with shuffling. With 16-row batches, the medians over 12 runs went from 676 to 689 ms and from 684 to 703 ms, respectively.Fixes #11743