Skip to content

inflate: skip the per-match bounds check in the fast loop#540

Open
jlucaso1 wants to merge 1 commit into
trifectatechfoundation:mainfrom
jlucaso1:perf/unchecked-match-copy
Open

inflate: skip the per-match bounds check in the fast loop#540
jlucaso1 wants to merge 1 commit into
trifectatechfoundation:mainfrom
jlucaso1:perf/unchecked-match-copy

Conversation

@jlucaso1

@jlucaso1 jlucaso1 commented Jul 1, 2026

Copy link
Copy Markdown

The inflate fast loop already guarantees INFLATE_FAST_MIN_LEFT bytes of output headroom before it runs, yet copy_match still recomputes a capacity clamp and does a bounds check on every single match. That work is redundant inside the fast loop.

This adds a copy_match_unchecked variant used only there, and bumps the margin to also cover the chunked copy's overshoot (260 + 32), so the per-match check can be safely elided. zlib-ng/libdeflate do the same thing.

Measured ~8% fewer instructions on inflate (perf stat, on a mix of protobuf-like data and the silesia corpus). The window-copy path is untouched.

Correctness: the full test-libz-rs-sys C-compat suite passes, plus a fuzz roundtrip (200k random inputs across sizes/levels) with a canary past the output buffer to catch any overshoot.

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