The Wayback Machine - https://web.archive.org/web/20211006154319/https://github.com/segmentio/kafka-go/pull/305
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

fix and optimize varint encoding #305

Merged
merged 4 commits into from Jul 8, 2019

Conversation

@achille-roussel
Copy link
Contributor

@achille-roussel achille-roussel commented Jul 8, 2019

I was looking into optimizing varint decoding because we have a use case where during CPU-intensive work, ~15% of the time is spent on this code path.

While writing the initial benchmarks to validate the change I noticed that encoding and decoding was broken for large integer values due to some mistakes in the way zig-zag encoding was being handled. This probably never triggered in practice because the varints are not used to encode values in the 2^56~2^64 range, but we're better off with a fix anyways ;)

The optimization yielded good results on the read path:

benchmark                old ns/op     new ns/op     delta
BenchmarkWriteVarInt     20.8          20.3          -2.40%
BenchmarkReadVarInt      93.3          38.0          -59.27%
Copy link
Contributor

@stevevls stevevls left a comment

🔥

@achille-roussel achille-roussel merged commit 03ea927 into master Jul 8, 2019
4 checks passed
@achille-roussel achille-roussel deleted the fix-and-optimize-varint-encoding branch Jul 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants