Repository navigation
fmt: bound line buffering for inputs without newlines - #10602
mattsu2020 wants to merge 1 commit into
Conversation
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
Merging this PR will improve performance by 3.19%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | Simulation | du_max_depth_balanced_tree[(6, 4, 10)] |
26.1 ms | 25.3 ms | +3.19% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing mattsu2020:fmt_devzero (5ee4496) with main (5de3062)
Footnotes
-
46 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. ↩
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
4e26790 to
4a1f5b0
Compare
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
sylvestre
left a comment
There was a problem hiding this comment.
too much added complexity for a rare case
please simplify it
|
GNU testsuite comparison: |
I tried to keep it as simple as possible |
|
GNU testsuite comparison: |
1405660 to
c3bf2d5
Compare
6b5bc2e to
5ee4496
Compare
|
I simplified the implementation quite a bit. |
a7fde05 to
ae8fd88
Compare
Limit each read to 1 MiB and end formatted paragraphs at the safety boundary so newline-free streams can produce output without waiting for EOF or another read. Carry incomplete UTF-8 characters and a trailing CR into the next read. Keep the formatting decision for each logical line, and let pass-through chunks supply a newline only at the logical line end. Cover stalled input, UTF-8 splits, LF/CRLF boundaries, EOF, and prefix handling in unit and integration tests.
ae8fd88 to
bb3cd08
Compare
Summary
fmtcurrently buffers an entire line before producing output, so newline-free streams such as/dev/zerocan grow memory indefinitely. Bound each read to 1 MiB and end the formatted paragraph at that boundary, without performing another potentially blocking read.Compatibility
Formatted logical lines exceeding the safety limit are intentionally split into bounded paragraphs. Their wrapping and indentation can differ from GNU
fmt, which retains arbitrarily large finite lines. Unformatted lines retain their bytes apart from the existing line-ending normalization.This bounds newline-free reads; it does not introduce a general size limit for paragraphs made of newline-terminated lines.
Validation
cargo test -p uu_fmt: 8 passed.cargo test --no-default-features --features fmt --test tests test_fmt::: 41 passed, 2 existing tests ignored.cargo clippy -p uu_fmt --tests -- -D warnings: passed, with an existing workspace warning about the unknownclippy::assert_is_emptylint.git diff --check: passed.Regression coverage includes stalled input at exactly 1 MiB, 2/3/4-byte UTF-8 characters across the limit, LF/CRLF, EOF at exact and repeated limits, and matching/nonmatching prefix and skip-prefix continuation.
Related: #10580