Add zlib-rs as an autogated backend for node:zlib - #7109
Open
guybedford wants to merge 1 commit into
Open
Conversation
guybedford
force-pushed
the
gbedford/zlib-rs
branch
from
August 24, 2026 23:18
f264eff to
84b362e
Compare
Backs the shared ZlibStream core with zlib-rs (libz-rs-sys), the memory-safe Rust implementation of the zlib C API, selected per stream by the new compression-rs autogate. This covers both node:zlib and the web CompressionStream/DecompressionStream API. The native chromium zlib remains the default. The z_stream ABI is identical between the two implementations, so the integration is a function dispatch table (ZlibDispatch) consulted at stream construction; node's dictionary/params escape hatches route through the same table via ZlibStream::dispatch(). The zlib-rs symbols are bridged from a translation unit that does not include the chromium zlib headers, since chromeconf.h renames all standard zlib identifiers (Cr_z_ mangling) - which is also why the unprefixed zlib-rs symbol names are collision-free in the binary. bench-zlib measures both backends on the streaming workload (1MB in 16KB chunks, level 6): zlib-rs measures ~34% faster deflate and ~17% faster inflate than the SIMD-enabled chromium zlib.
guybedford
force-pushed
the
gbedford/zlib-rs
branch
from
August 24, 2026 23:44
84b362e to
157884b
Compare
jasnell
approved these changes
Aug 24, 2026
jasnell
left a comment
Collaborator
There was a problem hiding this comment.
This would have been more difficult before the api/compression.{h/c++} change I just landed ;-)
npaun
reviewed
Aug 25, 2026
| "build_file_content": "exports_files([\"bin/wasm-opt\"])" | ||
| }, | ||
| { | ||
| "name": "binaryen_linux_arm64", |
Member
There was a problem hiding this comment.
Aside: I should make our script handle multi-arch packages like this more nicely.
npaun
reviewed
Aug 25, 2026
| }; | ||
|
|
||
| // Selects the backing zlib implementation via the compression-rs autogate. | ||
| const ZlibDispatch& getZlibDispatch(); |
Member
There was a problem hiding this comment.
nit: getZlibDispatch() to set up vs dispatch() to access isn't the clearest to me.
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.
This adds zlib-rs (libz-rs-sys), the memory-safe Rust implementation of the zlib C API, as an alternative backend for node:zlib's zlib streams, selected per context by the new
compression-rsautogate. The native chromium zlib remains the default.The z_stream ABI is identical between the two implementations, so the integration is a function dispatch table (
ZlibDispatch) consulted at context construction:bench-zlibmeasures both backends on the node:zlib streaming workload (1MB in 16KB chunks, level 6): zlib-rs is 34% faster on deflate and 17% faster on inflate than the SIMD-enabled chromium zlibThe full node:zlib test matrix passes with the gate both off and on (the @all-autogates variants exercise the zlib-rs path, including the dictionary and resizable-buffer tests).