Use klauspost/compress for tar and zip decompression - #41
Merged
Merged
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved blocking issues were identified.
Pull request overview
This PR switches TAR gzip decompression to Klauspost’s compatible implementation for improved performance while preserving behavior.
Changes:
- Use
klauspost/compress/gzipfor TAR decompression. - Add multistream and corrupt-header tests.
File summaries
| File | Description |
|---|---|
tar.go |
Uses Klauspost gzip for TAR decompression. |
tar_read_test.go |
Adds multistream and header-error coverage. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
RegisterDecompressor bypasses archive/zip's internal flate pool and klauspost's Reset wraps non-ByteReader inputs in a fresh bufio.Reader, so pool a bufio.Reader alongside the decoder and hand that to Reset.
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.
The module already depends on
klauspost/compressfor zstd; itsgzipsubpackage is a drop-in replacement for stdlib and aliasesErrChecksum/ErrHeaderto the stdlib sentinels, so no callers or existing tests change.Interleaved benchstat, arm64 darwin, n=10:
An isolated decoder A/B on text-like data (25% compression ratio, closer to real source archives than the random-payload fixtures) shows 1.44–1.88×. B/op drops 0.03–9.3% across the
.gzcases; allocs/op gains a fixed +2 per open from the reader setup.Stripped binary size for a minimal consumer grows by ~84 KB (+3.1%) since
archive/zipkeeps stdlibcompress/flatelinked, so klauspost's flate is additive rather than a replacement.Adds a multistream-gzip test (Alpine
.apkshape) and a corrupt-header test; both pass against stdlib and klauspost.For zip,
reader.RegisterDecompressor(zip.Deflate, ...)swaps in klauspost's flate on the existingarchive/zipreader. That bypassesarchive/zip's internal flate pool, and klauspost'sResetwraps any input lackingio.ByteReaderin a freshbufio.Reader(archive/zippasses anio.SectionReader), sozip.gopools a*bufio.Readeralongside the decoder and hands that toReset. Zero binary cost since klauspost's flate is already linked via gzip. AddsBenchmarkZipExtract(64×16 KiB deflated members, ~34% ratio):conda.gois left alone: its zip members areStore, so registering a deflate decompressor there does nothing.