Repository navigation
Decompression: a faster checksum, larger first-level tables - #74
Merged
Merged
Conversation
The Adler-32 checksum of each zlib stream is computed 32 bytes at a step: the sum and the weighted sum of each word of eight bytes come from two multiplications each, on its bytes spread into lanes of 16 bits, and the sums are reduced modulo 65521 as often as zlib reduces them. 9.3 GB/s against 5.5 for hash/adler32; TestAdler32 and FuzzAdler32 compare it with hash/adler32. The first level of the decoding tables is of 10 bits for literals and lengths and 7 for distances, where it was 9 and 6: fewer codes go through a second level. 11 bits cost more to build than they save on the short streams of PDF files. BenchmarkZlibCorpus decompresses the zlib streams of the tuning set of the public corpus, images left out as reading text leaves them, and TestCorpusLikeCompressZlib checks them against compress/zlib. On it: 281 ms to 255, 5.65 G instructions to 5.28. Reading the tuning set takes 1.33 percent fewer instructions; the JSON of all 3,253 files of the corpus cache and the fixtures is the same as on main. Tried and left out, as each measured worse: writing the literals of a round through a slice of known length, a refill of eight bytes in the block header, and entries that hold a pair of literals (their building costs more than they save on streams of 11 KB on average). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DzYLyEzLqkwuqPQ9LXgMpD
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 decompression item. A modest gain, and smaller than I estimated. No change to output.
Where the time was. On one worker, reading the tuning set spends about a fifth of its time decompressing zlib streams, mostly page content. Only 1.1% of decompressed bytes are streams decompressed twice, so keeping decoded streams wouldn't help; only a faster decoder would. On the new real-stream benchmark, the time split:
What changes
adler.go: the checksum computed 32 bytes at a step.hash/adler32.TestAdler32andFuzzAdler32compare the two.BenchmarkZlibCorpusdecompresses every zlib stream of the tuning set from the corpus cache, leaving out images since reading text doesn't decompress them.TestCorpusLikeCompressZlibchecks those 11,394 streams againstcompress/zlib. Both skip without the corpus.Results
Tried and left out, because each measured worse:
Same output
Corpus: the JSON output, warnings included, has the same SHA-256 as on main for all 3,253 files of the corpus cache and the fixtures.
Fuzzing with
-fuzzminimizetime 0s, nothing found:FuzzZlib(againstcompress/zlib)FuzzAdler32FuzzFiltersFuzzOpenFuzzPageFuzzAdler32is added to.github/fuzz-targets.txt, the full test suite passes, and the CHANGELOG has an entry under Unreleased.Why I'd stop here: what's left is the core decode loop, which is close to what pure Go allows without assembly or
unsafe.🤖 Generated with Claude Code
https://claude.ai/code/session_01DzYLyEzLqkwuqPQ9LXgMpD