Skip to content

Commit

Permalink
Use [T]::copy_within in EncoderWriter i/o [T]::rotate_left
Browse files Browse the repository at this point in the history
For now not doing the same in DecoderReader because benchmarks indicate
a performance regression and I’d like to take a closer look at it.  With
EncoderWriter benchmark results are as follows:

    encode_reuse_buf_stream:
               3    21.01 ns   +3.3135%   Regression    p = 0.00
              50    58.20 ns   +1.8117%   Regression    p = 0.00
             100    71.93 ns   -7.4010%   Improvement   p = 0.00
             500   237.47 ns   -0.3117%   Within noise  p = 0.02
            3072    1.283 µs   -2.5103%   Improvement   p = 0.00
         3145728    1.335 ms   +0.3749%   Within noise  p = 0.03
        10485760    4.442 ms   +0.8301%   Within noise  p = 0.00
        31457280   14.135 ms   -0.0776%   No change     p = 0.50
  • Loading branch information
mina86 committed Jan 20, 2023
1 parent 92e94d2 commit 043f723
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/write/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,12 @@ impl<'e, E: Engine, W: io::Write> EncoderWriter<'e, E, W> {
self.panicked = false;

res.map(|consumed| {
debug_assert!(consumed <= current_output_len);

if consumed < current_output_len {
self.output_occupied_len = current_output_len.checked_sub(consumed).unwrap();
self.output_occupied_len = current_output_len.checked_sub(consumed).unwrap();
if self.output_occupied_len > 0 {
// If we're blocking on I/O, the minor inefficiency of copying bytes to the
// start of the buffer is the least of our concerns...
// TODO Rotate moves more than we need to; copy_within now stable.
self.output.rotate_left(consumed);
} else {
self.output_occupied_len = 0;
self.output
.copy_within(consumed..consumed + self.output_occupied_len, 0)
}
})
}
Expand Down

0 comments on commit 043f723

Please sign in to comment.