Repository navigation
Inflate each entry in one call, straight into its output buffer - #4
Merged
Merged
Conversation
inflate read the stream through flate2's DeflateDecoder, a reader: input went through a 32 KiB buffer, and the inflater decoded into its own 32 KiB window and copied each piece out. One Decompress::decompress_vec call with Finish over the whole payload lets the inflater write straight into the output and use it as its history. One spare byte of capacity still catches a stream that runs past its declared size, and anything short of the stream's end or of the declared size is still an error; a new test pins those cases, and passes on the old code too. 16 MiB of text: M4 757 -> 863 MB/s, M5 796 -> 925, i7-8700K 529 -> 607. Small entries are unchanged: their cost is the inflater's setup and its Huffman tables, not the copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
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.
What
inflateused to read each entry through flate2'sread::DeflateDecoder. That reader copies the input through a 32 KiB buffer, and its inflater decodes into its own 32 KiB window and then copies each piece out.It now makes one
Decompress::decompress_veccall withFlushDecompress::Finishover the whole payload. With the whole stream andFinishup front, the inflater writes straight into the output buffer and uses it as its history.The size checks are unchanged in effect:
DecompressionFailed.inflate_holds_streams_to_their_declared_sizepins these cases for empty, one-byte, text and incompressible bodies. It passes on the old code too.No dependency change.
Measured (fastest round,
examples/bench.rs)Small entries don't move: their time goes to the inflater's setup and each stream's Huffman tables, not to the copies.
Two other options were measured and are not in this PR:
zlib-rsbackend inflates 2.3–2.6× faster on the M4/M5 (16 MiB at 2.1–2.3 GB/s, small entries at 660–940 MB/s), but only 1.15–1.5× on the i7-8700K. It would replace miniz_oxide, which forbidsunsafe, with a crate that uses it. That trade is the maintainer's call.Correctness
cargo fmt --check,cargo clippy --all-targets -- -D warningsandcargo testpass on aarch64-apple-darwin and x86_64-linux.🤖 Generated with Claude Code