perf: use klauspost/compress for gzip and flate decompression - #19
Open
burruplambert wants to merge 1 commit into
Open
perf: use klauspost/compress for gzip and flate decompression#19burruplambert wants to merge 1 commit into
burruplambert wants to merge 1 commit into
Conversation
This was referenced Jul 31, 2026
The stdlib compress/gzip and compress/flate use a slower Huffman decoder. klauspost/compress is a drop-in replacement with a faster implementation, measured at ~5% total CPU reduction in production profiling of a high-throughput HTTP client workload.
burruplambert
force-pushed
the
perf/klauspost-decompression
branch
from
August 1, 2026 13:06
e0b3bdd to
972a168
Compare
Author
|
Checked the drop-in claim rather than relying on it. Compared klauspost against stdlib across 14 malformed-input cases - empty input, non-gzip data, truncated header, truncated body, truncated trailer, bad magic, bad compression method, corrupt CRC, corrupt size, corrupt deflate stream, trailing garbage, and concatenated streams, plus a corrupt raw flate stream. Every case produced the identical outcome, including the exact error text - So callers that inspect or match on decompression errors see no change. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Drop-in replacement of compress/gzip and compress/flate with github.com/klauspost/compress for response body decompression.
The klauspost implementation has a significantly faster Huffman decoder. In CPU profiling of a high-throughput production client workload, stdlib gzip decompression accounted for roughly 5% of total CPU, and swapping the import removed most of that.
Note: the package test suite reports a failure at the end of any full run because TestMain's goroutine leak checker flags its own goroutine. That is pre-existing on master and unrelated to this change.