New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
zlib: add zstd support #52100
base: main
Are you sure you want to change the base?
zlib: add zstd support #52100
Conversation
Review requested:
|
ec19b6e
to
28914c7
Compare
Alright, got up to making the basics (seemingly) work: $ out/Debug/node -p 'zlib.zstdDecompressSync(zlib.zstdCompressSync("Hello World")).toString()'
Hello World |
383ff46
to
47c7ab8
Compare
Fixes: nodejs#48412 PR-URL: nodejs#52100
Fixes: nodejs#48412 PR-URL: nodejs#52100
Fixes: nodejs#48412 PR-URL: nodejs#52100
Fixes: nodejs#48412 PR-URL: nodejs#52100
Fixes: nodejs#48412 PR-URL: nodejs#52100
Fixes: nodejs#48412 PR-URL: nodejs#52100
Fixes: nodejs#48412 PR-URL: nodejs#52100
The
notable-change
Please suggest a text for the release notes if you'd like to include a more detailed summary, then proceed to update the PR description with the text or a link to the notable change suggested text comment. Otherwise, the commit will be placed in the Other Notable Changes section. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've only looked at the usage of the Zstd API. It looks about right, I've left some minor comments. I'm not familiar with the code, and it isn't clear to me exactly how DoThreadPoolWork()
is called, so I can't be completely confident. But broadly it looks right.
One thing to consider is that some advanced parameters directly can cause Zstd to allocate a lot of memory (e.g. setting ZSTD_c_hashLog == ZSTD_c_chainLog == ZSTD_c_windowLog == 31
will cause Zstd to allocate at least 6 GB during compression). Additionally, the parameter ZSTD_c_nbWorkers
will cause Zstd to spawn worker threads during compression.
This normally isn't an issue, because the author of the code is trusted. I assume that this is also the threat model for NodeJS. But, because it is JS, I did want to raise the point.
There must be at least compression level support What do you mean at runtime? You can change any parameters you want before the (de)compression starts. After that, changing compression parameters generally isn't allowed.
If the input size is known in advance, then you can use If the input size is only approximately known, but may be wrong, then Zstd also supports setting |
Thanks for confirming. The "at runtime" refers to the deflate-specific feature ( Updated the PR description to correct this part.
Ah, thanks. Saw |
Rebased after the fixes to ensure it still lands cleanly. |
Looking at the test failures, they look unrelated at first glance (different tests on different OS, not related to compression afaict). Resuming the build to see if the are flakes. |
Maybe it's possible to bump |
Happy to rerun the import. I think right now I'm also looking for signal that this is something that other collaborators want in core. Otherwise rebasing (potentially) and reimporting wouldn't really be worth it - it would just bitrot again. |
I cannot speak on behalf of collaborators, but imho W3C community would certainly like to see it in the core 🧐 |
Adds
ZstdCompress
andZsdDecompress
to thezlib
module which can be used to compress/decompress with the Zstandard ("zstd") algorithm.Notable omissions:
zlib.md
don't call out any params beyond the basic compression level.The code follows similar patterns to the PR that added Brotli support. Just that instead of brotli, it adds the equivalent zstd APIs. Just like Brotli, this required separate compression/decompression context objects.
Zstd itself has been around and stable for multiple years but this PR is early in terms of web support: It only just starts shipping by default in Chrome 123. On the other hand, by shipping in Chrome it will soon be supported quite widely on the web. Firefox also signaled support (https://bugzilla.mozilla.org/show_bug.cgi?id=1301878#c65).
Official support in node.js would allow passing additional WPTs around
fetch
(nodejs/undici#2847).