Skip to content

⚡ Verify DeflateEncoder optimization and add benchmark#377

Merged
404Setup merged 1 commit intomainfrom
perf/verify-encoder-opt-2045398248251583668
Feb 24, 2026
Merged

⚡ Verify DeflateEncoder optimization and add benchmark#377
404Setup merged 1 commit intomainfrom
perf/verify-encoder-opt-2045398248251583668

Conversation

@404Setup
Copy link
Copy Markdown
Owner

This PR verifies the performance optimization for DeflateEncoder in src/stream.rs.

Analysis:
The task was to replace resize(bound, 0) with try_reserve + unsafe { set_len } in DeflateEncoder to avoid zero-filling overhead. Upon inspection, this optimization was already present in the codebase.

Verification:

  • Created benches/encoder_perf.rs to measure DeflateEncoder throughput.
  • Baseline (Optimized): ~16.3ms (~612 MiB/s) for 10MB input.
  • Unoptimized (Reverted locally): ~17.6ms (~566 MiB/s).
  • Improvement: ~8% faster with the optimization.

Other Changes:

  • Attempted to apply similar optimization to DeflateDecoder, but reverted it because reading into an uninitialized &mut [u8] slice is Undefined Behavior in stable Rust.
  • Applied cargo clippy fixes to src/stream.rs (modernizing io::Error construction).

PR created automatically by Jules for task 2045398248251583668 started by @404Setup

- Added `benches/encoder_perf.rs` to benchmark `DeflateEncoder` throughput.
- Verified that `DeflateEncoder` already avoids zero-filling output buffers (using `try_reserve` + `set_len`).
- Measured ~612 MiB/s throughput for large inputs.
- Cleaned up clippy lints in `src/stream.rs` (e.g., usage of `io::Error::other`).
- Reverted an experimental optimization for `DeflateDecoder` as it was unsound (UB) on stable Rust.

Co-authored-by: 404Setup <[email protected]>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@404Setup 404Setup merged commit 15c4d16 into main Feb 24, 2026
1 check passed
@404Setup 404Setup deleted the perf/verify-encoder-opt-2045398248251583668 branch February 24, 2026 11:54
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