pr: fix OOM on infinite streams and optimize merge mode - #13540
Open
0xScodyx wants to merge 5 commits into
Open
Conversation
0xScodyx
force-pushed
the
fix-pr-oom-and-optimize
branch
from
July 23, 2026 15:14
814c9da to
2d256b0
Compare
0xScodyx
force-pushed
the
fix-pr-oom-and-optimize
branch
from
July 23, 2026 15:52
063df07 to
af76813
Compare
|
GNU testsuite comparison: |
Devel08
reviewed
Jul 24, 2026
| loop { | ||
| // Skip pages before start_page without allocating FileLine objects. | ||
| // This avoids wasting memory when piping infinite output through | ||
| // `pr --start-page=N --end-page=M`. |
Contributor
There was a problem hiding this comment.
there's no such flag as --start-page=N, neither in GNU nor in uutils
Author
There was a problem hiding this comment.
it was just a personal note in the code i forgot to remove
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
Fix OOM on infinite streams (
/dev/zero,/dev/random) in both single-file and-mmerge mode. Additionally optimized merge mode to be ~2x faster than GNU pr.Changes
MAX_CHUNK_SIZE = 256KB: artificial newline when input has no line/FF separatorsread_one_page(track_content=false): skip pages outside--pagesrange without allocationwrite_merge_page(): specialized for-mmode with pre-allocated buffers and direct byte writes (no intermediate String allocations)BufWriter: batch stdout writes, reduced syscall overhead significantlyget_pages(),get_file_line_groups(),to_table_merged(), etc.Benchmarks (200MB × 2 files,
-mmerge mode)Tests
test_prtests pass (including memory-limit test)/dev/zerounderulimit -v 300000runs without OOM in both modesCloses #13479