Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce allocations in flate decompressor and minor code improvements #869

Merged
merged 11 commits into from
Oct 10, 2023
Prev Previous commit
Next Next commit
made benchmarks more accurate by removing io.Copy call
as io.Copy is just an alias for io.CopyBuffer, but passing nil instead of the actual buffer, it is being allocated internally. So better to pass it manually
  • Loading branch information
flrdv committed Oct 8, 2023
commit a4773a95c30044de0082747b2319dfcba3f7b7e1
4 changes: 3 additions & 1 deletion flate/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ func benchmarkDecode(b *testing.B, testfile, level, n int) {
w.Close()
buf1 := compressed.Bytes()
buf0, compressed, w = nil, nil, nil
const ioCopyBuffSize = 32 * 1024 // taken from io.copyBuffer, in case passed buf==nil
ioCopyBuff := make([]byte, ioCopyBuffSize)
runtime.GC()
b.StartTimer()
r := NewReader(bytes.NewReader(buf1))
res := r.(Resetter)
for i := 0; i < b.N; i++ {
res.Reset(bytes.NewReader(buf1), nil)
io.Copy(io.Discard, r)
io.CopyBuffer(io.Discard, r, ioCopyBuff)
}
}

Expand Down