Repository navigation
Conversation
Merging this PR will regress 1 benchmark1 warning
Warning Please fix the performance issues or acknowledge them on CodSpeed. Performance Changes
Tip Investigate this regression by commenting Comparing Footnotes
|
1fa4ff9 to
139a237
Compare
|
@codspeedbot fix this regression |
| // be printed by the producer thread. | ||
| // A small buffer batches redirected output without a large allocation | ||
| // for invocations that only print a few totals. | ||
| let capacity = if stdout.is_terminal() { 0 } else { 2 * 1024 }; |
There was a problem hiding this comment.
why 2 KiB and not the default capacity?
| // A small buffer batches redirected output without a large allocation | ||
| // for invocations that only print a few totals. | ||
| let capacity = if stdout.is_terminal() { 0 } else { 2 * 1024 }; | ||
| let mut output = BufWriter::with_capacity(capacity, stdout); |
There was a problem hiding this comment.
with --verbose, the "ignored" lines printed by the traversal thread with println! now come before the buffered stats when stdout is a file, so the order differs from main.
could you please route them through the printer or flush before them? and please add a test with -v --exclude
| } | ||
|
|
||
| #[test] | ||
| fn test_buffered_output_flushes_final_total() { |
There was a problem hiding this comment.
this one passes on main too, no? it doesn't really test the buffering
| } | ||
| ucmd.set_stdout(std::fs::File::create("/dev/full").unwrap()) | ||
| .fails_with_code(1) | ||
| .stderr_contains("No space left on device") |
There was a problem hiding this comment.
stderr_does_not_contain("panicked") isn't needed, fails_with_code + stderr_contains is enough
|
codspeed reports a 13.86% regression, could you please check where it comes from? |
The current head of this PR ( CauseThe report above was produced for an earlier commit,
Current head
I couldn't measure memory in my environment, so these memory numbers are estimates. CodSpeed hasn't benchmarked I did measure CPU simulation locally,
The speedup from buffering is still there, and the time doesn't go up on any If CI still shows a memory regression after it runs, comment Summary
Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot. |
0f16a92 to
ca21e3a
Compare
|
GNU testsuite comparison: |
| let mut output = if stdout.is_terminal() { | ||
| BufWriter::with_capacity(0, stdout.lock()) | ||
| } else { | ||
| // Batch lines without retaining the default 8 KiB throughout traversal. |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
ca21e3a to
92773b2
Compare
| BufWriter::with_capacity(0, stdout.lock()) | ||
| } else { | ||
| // 1 KiB limits memory retained throughout traversal while batching lines. | ||
| // A 10,000-file check ran within 2% of the default 8 KiB buffer's time. |
There was a problem hiding this comment.
so does performance regress by 2% by reducing buffer size from 8 KiB to 1 KiB?
and why 1 KiB, not 512 B or 2 KiB?
There was a problem hiding this comment.
Fair point—the earlier check didn’t justify choosing 1 KiB. I’ve switched to BufWriter::new() and removed the 2% comment.
I compared 512 B, 1 KiB, 2 KiB, and the default. Timings varied too much to draw a reliable conclusion, but the default used 35 writes on the 10,000-file case, versus 273 with 1 KiB and 10,001 without buffering. The tradeoff is a larger fixed buffer, currently 8 KiB.
There was a problem hiding this comment.
I think the default BufWriter buffer size is likely the best choice unless benchmarks provide evidence otherwise.
6662750 to
52e2f2a
Compare
52e2f2a to
b0e4ca7
Compare
b0e4ca7 to
eed52a9
Compare
eed52a9 to
8466378
Compare
8466378 to
e1487ac
Compare
585bc02 to
a1f4470
Compare
| let stdout = stdout().lock(); | ||
| let mut output = if stdout.is_terminal() { | ||
| // Keep terminal output immediate. | ||
| BufWriter::with_capacity(0, stdout) |
There was a problem hiding this comment.
Consider introducing an enum to avoid initialising a BufWriter in the unbuffered case, something like:
enum OutputWriter<'a> {
Immediate(io::StdoutLock<'a>),
Buffered(BufWriter<io::StdoutLock<'a>>),
}f954161 to
070d4ce
Compare
|
The new approach using generics results in code size +2208 bytes: $ git checkout -q a1f4470
$ CARGO_PROFILE_RELEASE_LTO=off cargo build -p uu_du -q -r && wc -c < target/release/du
2031440
$ git checkout -q 070d4ce
$ CARGO_PROFILE_RELEASE_LTO=off cargo build -p uu_du -q -r && wc -c < target/release/du
2032736What is the intent of the changes in 070d4ce? |
| } | ||
| } | ||
|
|
||
| fn print_stats_to( |
There was a problem hiding this comment.
Functions taking a writer should be named with write_ prefix, with the writer being the first parameter after &self. Also does the function need to own the writer, could take &mut impl OsWrite, no?
There was a problem hiding this comment.
Could call the writer writer instead of output too.
070d4ce to
b5915c8
Compare
b5915c8 to
5a647c7
Compare
|
5a647c7 got a bit better for code size $ git checkout -q 5a647c7762bc6cff663f78cc91d297ba7968cf72
$ CARGO_PROFILE_RELEASE_LTO=off cargo build -p uu_du -q -r && wc -c < target/release/du
2030752 |
Send stats and verbose messages through one writer to preserve their order. Flush redirected output before reporting traversal errors and when printing finishes so write failures reach the caller. Borrow the selected writer so terminals need no extra buffer and both output modes share one copy of the printing loop.
5a647c7 to
e522982
Compare
Buffer output to files and pipes, preserve immediate terminal output, and flush before diagnostics and on completion. Add tests for final totals and flush failures. A 10,000-file check reduced write calls from 10,001 to 7.
Validation: 108 du integration tests pass. Verified unchanged output with non-UTF-8 names, totals, NUL separators, and timestamps.
Closes #9146