pr: stream simple layouts for non-file inputs #11244
the list of commits isn't ideal, could you please improve it? thanks
GNU testsuite comparison:
Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!
Congrats! The gnu test tests/tail/pipe-f is now passing!
<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->
Merging this PR will regress 1 benchmark
<details>
<summary><b>2 warnings, 1 note</b></summary>
:warning: 124 benchmarks are dominated by system calls
> System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.
> Learn more about system calls
> See affected benchmarks
:warning: 4 benchmarks with a significant change ran on different hardware
> Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
> Learn more about Macro Runners
> See affected benchmarks
:information_source: 1 benchmark has no flamegraph
> The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.
> See affected benchmarks
</details>
⚡ 3 improved benchmarks ❌ 1 regressed benchmark ✅ 411 untouched benchmarks ⏩ 74 skipped benchmarks[^skipped]
[!WARNING]
Please fix the performance issues or acknowledge them on CodSpeed.
Performance Changes
| | Mode | Benchmark | BASE | HEAD | Efficiency |
| --- | ---- | --------- | ------ | ------ | ---------- |
| ❌ | CPU Simulation | ` df_deep_directory | 898.5 µs | 941.1 µs | -4.52% |
| ⚡ | Memory | timeout_enforced | 167.5 KB | 88.7 KB | +88.88% |
| ⚡ | CPU Simulation | [ socket_addrs_direct[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Apr_zero?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Asocket_addrs_direct%255B100000%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 132.1 µs | 105.1 µs | +25.7% |
| ⚡ | CPU Simulation | [ hostname_ip_lookup[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Apr_zero?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Ahostname_ip_lookup%255B100000%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 573.3 µs | 545.5 µs | +5.09% |
[!TIP]
Investigate this regression by commenting @codspeedbot fix this regression` on this PR, or directly use the CodSpeed MCP with your agent.
---
<sub>Comparing <code>mattsu2020:pr_zero</code> (d79808e) with <code>main</code> (ce58468)[^unexpected-base]</sub>
<a href="https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Apr_zero?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>
[^skipped]: 74 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.
[^unexpected-base]: No successful run was found on <code>main</code> (f02ef8e) during the generation of this report, so ce58468 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.
GNU testsuite comparison:
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/cut/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.
<!-- gnu-comment-bot -->
GNU testsuite comparison:
Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Streaming rejects invalid UTF-8 with exit 1, but the buffered path uses from_utf8_lossy and GNU passes bytes through — so the same bytes succeed from a file yet fail from a FIFO, which is the opposite of the file/FIFO parity this PR is for. Drop the validation and stream the bytes.
Both parity tests land in the lines_to_read_for_page == 0 fallback, so neither actually runs the streaming code. Add a case that streams a real multi-page layout (e.g. -h H -l 5 over ~20 lines) and compares file vs FIFO output.
Excluding stdin means pr < /dev/zero and cat /dev/zero | pr still read to EOF and OOM; only named device/FIFO paths are fixed, not the pipe case from the issue.
Byte-at-a-time writes to an unbuffered StdoutLock cost a syscall per byte on input like /dev/zero; wrap the lock in a BufWriter.
This re-implements the get_pages/print_page paging, trailer and \n\f logic as a parallel state machine, which will drift from the buffered path as it changes — better to factor the shared paging out than duplicate it.
I'll make the correction
I'll make the correction
I'll make the correction
I definitely agree
I will keep the source code separate.
Conflicting
@mattsu2020 still conflicting
@mattsu2020 Some clippy lints failing...
@sylvestre @cakebaker Can you please take a look at this pr?
read errors lose the file name here: pr /tmp now prints pr: Is a directory instead of pr: /tmp: Is a directory.
could you please map it to ReadPath (or keep directories on the old path) and add a test?
why only unix? type x | pr on windows still reads everything into memory, a comment saying it's a known limitation would be fine
fixed it.added test
Added comments.
How about wasi? rustix has stat for wasi. Also .as_fd() can be omitted.
Thanks.
I think I can write this cleanly.
sylvestre
mattsu2020
Summary
This PR adds a streaming path for simple
prlayouts so inputs such ascharacter devices and FIFOs can be processed incrementally instead of buffering
the entire input in memory.
The main goal is to avoid OOM-like behavior for inputs such as
/dev/zero,where
prcan produce output line by line without waiting for a full read.What changed
prlayouts- character-device input
- FIFO/file parity for layouts that actually exercise the streaming path
- FIFO/file parity in zero-content-line fallback cases
Related