Repository navigation
Conversation
When reading line-at-a-time from stdin, BufWriter only flushed on exit, so an interactive session showed no converted output until the user quit. Match cut by skipping BufWriter when stdout is a terminal, and on the buffered path flush once per input chunk that completed a line, so piped line-at-a-time producers also see prompt output without a write per line on large inputs. Fixes uutils#11091
Merging this PR will regress 1 benchmark
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ❌ | factor_three_39_bit_primes |
715.7 ms | 795.8 ms | -10.06% |
| ⚡ | factor_five_38_bit_primes |
2 s | 1.8 s | +13.46% |
| ⚡ | expand_many_lines[100000] |
115.9 ms | 106 ms | +9.31% |
| ⚡ | expand_custom_tabstops[50000] |
31.6 ms | 29.7 ms | +6.51% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing r3wretrhy:expand-unexpand-stdin-flush (a56ecf7) with main (98194d4)2
Footnotes
-
391 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. ↩
-
No successful run was found on
main(9f52800) during the generation of this report, so 98194d4 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
|
Can we avoid large performance drop? |
Keep the plain BufWriter<Stdout> path and flush before the next read only when the input is stdin and stdin is not a regular file. File arguments and redirected regular files are fully buffered again, avoiding the slowdown.
|
GNU testsuite comparison: |
|
@oech3 The perf drop is fixed in 0a02252, it only flushes when stdin is a pipe/tty now. CodSpeed shows expand_many_lines +9% and expand_custom_tabstops +6.5% faster. The factor regression looks unrelated since this PR doesn't touch factor. Also enabled rustix for all unix targets so it builds on macOS/BSD. |
When stdin is read line-at-a-time (interactive terminal, or any producer that pauses between lines),
expand/unexpandheld converted output in aBufWriterand only flushed on exit. An interactive session therefore showed no converted line until the user quit, while GNU shows each line immediately.Like
cut, skipBufWriterwhen stdout is a terminal. On the buffered path, flush once per input chunk that completed a line (before the next read), so line-at-a-time pipes also see output promptly without a write per line on large inputs.Added
test_stdin_tty_flushes_each_linetotest_expand.rsandtest_unexpand.rs.Closes #11091