Skip to content

Auto-port 5.0: Codec-compression: Add zlib decompressors - #17167

Merged
chrisvest merged 1 commit into
5.0from
auto-port-pr-17155-to-5.0
Jul 28, 2026
Merged

chrisvest merged 1 commit into
5.0from
auto-port-pr-17155-to-5.0

Conversation

@netty-project-bot

Copy link
Copy Markdown
Contributor

Auto-port of #17155 to 5.0
Cherry-picked commit: 341a5f7


Motivation:

The new decompressor API work in #15667 is being split into smaller, independently reviewable changes as tracked by #16743. The core decompressor API has already landed in #16745; this PR extracts the JDK zlib-specific portion.

Modification:

  • Add a JDK-backed zlib decompressor exposed through JdkZlibDecompressor.builder().
  • Support ZLIB, GZIP, raw-deflate, and ZLIB-or-raw auto-detection, preset dictionaries, bounded output allocation, and concatenated GZIP members.
  • Add focused decompressor contract and regression tests.
  • Port Fix GZIP FEXTRA extra-field handling in JdkZlibDecoder #16951's GZIP FEXTRA handling and concatenated-member regression coverage.
  • Harden EOF/truncation handling, output-buffer ownership, inflater cleanup, allocation validation, and GZIP header validation.
  • Cover direct-buffer input across partial output consumption.

The new pull API intentionally uses only the JDK implementation. The existing JZlibDecoder selection behavior in the established ZlibCodecFactory.newZlibDecoder(...) APIs remains unchanged.

Result:

ZLIB, GZIP, and raw-deflate streams can be decompressed through the new pull-based Decompressor API. The implementation also supports wrapper auto-detection and concatenated GZIP streams without adding a second JZlib-backed pull implementation or changing ZlibCodecFactory.

Performance:

A temporary JMH comparison of one-shot construction and ZLIB decompression on OpenJDK 21.0.11 found the JDK implementation faster for the tested payloads:

Uncompressed size JDK JZlib JDK advantage
1 KiB 187,927 ops/s 76,748 ops/s 2.45x
150 KiB ~5,291-5,353 ops/s ~1,686-1,711 ops/s ~3.1x
1 MiB 916.7 ops/s 536.2 ops/s 1.71x

The benchmark used one thread, two forks, 3 x 500 ms warmups, and 5 x 500 ms measurements per fork. The 150 KiB cases covered heap/direct input and 8 KiB/1 MiB maximum allocations. These results are directional rather than a universal performance claim, but showed no performance reason to retain the JZlib variant.

Verification:

  • ./mvnw -pl codec-compression test: 411 tests passed with no failures or errors.
  • JdkZlibDecompressorTest: 33 focused cases passed.
  • Checkstyle, Java compilation, module generation, and packaging completed successfully.

Part of #16743.

Motivation:

The new decompressor API work in #15667 is being split into smaller,
independently reviewable changes as tracked by #16743. The core
decompressor API has already landed in #16745; this PR extracts the JDK
zlib-specific portion.

Modification:

* Add a JDK-backed zlib decompressor exposed through
`JdkZlibDecompressor.builder()`.
* Support ZLIB, GZIP, raw-deflate, and ZLIB-or-raw auto-detection,
preset dictionaries, bounded output allocation, and concatenated GZIP
members.
* Add focused decompressor contract and regression tests.
* Port #16951's GZIP FEXTRA handling and concatenated-member regression
coverage.
* Harden EOF/truncation handling, output-buffer ownership, inflater
cleanup, allocation validation, and GZIP header validation.
* Cover direct-buffer input across partial output consumption.

The new pull API intentionally uses only the JDK implementation. The
existing `JZlibDecoder` selection behavior in the established
`ZlibCodecFactory.newZlibDecoder(...)` APIs remains unchanged.

Result:

ZLIB, GZIP, and raw-deflate streams can be decompressed through the new
pull-based `Decompressor` API. The implementation also supports wrapper
auto-detection and concatenated GZIP streams without adding a second
JZlib-backed pull implementation or changing `ZlibCodecFactory`.

Performance:

A temporary JMH comparison of one-shot construction and ZLIB
decompression on OpenJDK 21.0.11 found the JDK implementation faster for
the tested payloads:

| Uncompressed size | JDK | JZlib | JDK advantage |
|---:|---:|---:|---:|
| 1 KiB | 187,927 ops/s | 76,748 ops/s | 2.45x |
| 150 KiB | ~5,291-5,353 ops/s | ~1,686-1,711 ops/s | ~3.1x |
| 1 MiB | 916.7 ops/s | 536.2 ops/s | 1.71x |

The benchmark used one thread, two forks, 3 x 500 ms warmups, and 5 x
500 ms measurements per fork. The 150 KiB cases covered heap/direct
input and 8 KiB/1 MiB maximum allocations. These results are directional
rather than a universal performance claim, but showed no performance
reason to retain the JZlib variant.

Verification:

* `./mvnw -pl codec-compression test`: 411 tests passed with no failures
or errors.
* `JdkZlibDecompressorTest`: 33 focused cases passed.
* Checkstyle, Java compilation, module generation, and packaging
completed successfully.

Part of #16743.

---------

Co-authored-by: multicode <[email protected]>
(cherry picked from commit 341a5f7)
@chrisvest chrisvest added this to the 5.0.0.Final milestone Jul 28, 2026
@chrisvest
chrisvest enabled auto-merge (squash) July 28, 2026 18:30
@chrisvest
chrisvest merged commit 5070b20 into 5.0 Jul 28, 2026
13 checks passed
@chrisvest
chrisvest deleted the auto-port-pr-17155-to-5.0 branch July 28, 2026 19:32
@testlens-app

testlens-app Bot commented Jul 28, 2026

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: be7a3a7
▶️ Tests: 40201 executed
⚪️ Checks: 12/12 completed


Learn more about TestLens at testlens.app.

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.

3 participants