diff --git a/crates/async-compression/src/generic/write/buf_writer.rs b/crates/async-compression/src/generic/write/buf_writer.rs index 22f677e5..8db1797b 100644 --- a/crates/async-compression/src/generic/write/buf_writer.rs +++ b/crates/async-compression/src/generic/write/buf_writer.rs @@ -136,7 +136,13 @@ impl BufWriter { ) -> Poll> { ready!(self.partial_flush_buf(poll_write))?; - if self.written > 0 { + // when the flushed data is larger than or equal to half of yet-to-be-flushed data, + // the copyback could use version of memcpy that do copies from the head of the buffer. + // Anything smaller than that, an overlap would happen that forces use of memmove. + if self.written >= (self.buffered / 3) + || self.written >= 512 + || self.buffered == self.buf.len() + { self.remove_written(); }