Closed odeke-em closed 6 months ago
The overall change focuses on optimizing the encoding of variable integers by introducing a more efficient handling mechanism when writing to io.Writer
interfaces in Go. It specifically improves the EncodeVarint
function to check for io.ByteWriter
implementation, minimizing overhead in scenarios where direct byte writing is possible. Additionally, it addresses performance concerns in encoding processes, particularly in contexts like IAVL node byte writing, by streamlining the varint encoding to reduce unnecessary memory operations.
Files | Change Summary |
---|---|
internal/encoding/bench_test.go |
Introduces benchmarking for varint encoding using binary encoding. |
internal/encoding/encoding.go |
Optimizes EncodeVarint to check for io.ByteWriter and uses fVarintEncode for efficient varint encoding. Keeps EncodeVarintSize unchanged. |
Objective | Addressed | Explanation |
---|---|---|
Change IAVL node.writeBytes to take in bytes.Buffer (#891) | ❌ | The changes focus on optimizing varint encoding but do not directly modify IAVL node.writeBytes to use bytes.Buffer . The objective of removing buffer pools overhead in node.WriteBytes by directly using bytes.Buffer.WriteByte is not addressed in the provided changes. |
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
Kindly cc-ing @ValarDragon
@mergifyio backport release/v1.x
backport release/v1.x
@mergifyio backport release/v1.1.x
@mergifyio backport release/v1.x.x
backport release/v1.1.x
backport release/v1.x.x
Thanks for the reviews Dev & Marko!
This change speeds up EncodeVarint by testing if the input writer implements io.ByteWriter and if so, goes to use our hand-rolled varint encoder, instead of using the awkward standard libary encoding/binary.PutVarint that requires a byteslice, which we also retrofitted using a bytearray pool. While here, added parity tests to ensure that we get the exact same results as with the Go standard library's encoding/binary package with caution from https://cyber.orijtech.com/advisory/varint-decode-limitless and also added benchmarks whose results reflect the change in just the benchmark initially
Fixes #891