Skip to content

Inflate each entry in one call, straight into its output buffer - #4

Merged
xbmc4lyfe merged 1 commit into
mainfrom
claude/inflate-direct
Nov 6, 2026
Merged

xbmc4lyfe merged 1 commit into
mainfrom
claude/inflate-direct

Conversation

@xbmc4lyfe

Copy link
Copy Markdown
Collaborator

What

inflate used to read each entry through flate2's read::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_vec call with FlushDecompress::Finish over the whole payload. With the whole stream and Finish up front, the inflater writes straight into the output buffer and uses it as its history.

The size checks are unchanged in effect:

  • Too long. The output gets one spare byte of capacity, so a stream that runs past its declared size fills it and is rejected.
  • Too short or truncated. A stream that ends early, or is cut before its end, is still DecompressionFailed.
  • Trailing bytes. Bytes after the end of the stream are still ignored.
  • New test. inflate_holds_streams_to_their_declared_size pins 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)

case M4 Air M5 Air (load ~180) i7-8700K (load ~24)
inflate-16M 757–768 → 863–881 MB/s 723–796 → 879–925 MB/s 486–529 → 537–607 MB/s
inflate-2000x4K 388 → 396 MB/s 400–405 → 406–415 MB/s 223–230 → 213–224 MB/s

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:

  • Calling miniz_oxide's core decoder directly (no 32 KiB window at all) gained 6–15% on small entries only. That isn't worth changing the dependency.
  • flate2's zlib-rs backend 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 forbids unsafe, with a crate that uses it. That trade is the maintainer's call.

Correctness

  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test pass on aarch64-apple-darwin and x86_64-linux.

🤖 Generated with Claude Code

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T19:16:48.974041Z c39aaa0 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@xbmc4lyfe
xbmc4lyfe merged commit 680cb5f into main Nov 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant