-
Notifications
You must be signed in to change notification settings - Fork 50
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
Mediocre deflate compression compared to Node.js's zlib #77
Comments
The compression ratio shouldn't be significantly different to what the zlib library does, so I will look into it. |
Ah, my mistake there. I see that now - |
It looks like using flate2 with the original C miniz gives the same result, while the zlib (library) back-end for flate2 and deflate-rs gives a similar result to the zlib binding in node.js. (flate2 with zlib backend should in theory be the same since it uses the same library underneath.) Not all files give the same unexpected bad compression level, but e.g this ends up with more than twice the compressed size with miniz/miniz_oxide than zlib/deflate-rs. Could maybe the block type selection algorithm that needs tweaking (something that can make a large difference on short data if the wrong type is chosen). |
To expand on this, currently miniz_oxide (and miniz) decides whether to use static or dynamic huffman codes simply based on whether the number of lz-compressed bytes (i.e number of literals and length/distance pairs) the compression of the block resulted in. Static codes are used if the number of lz bytes are less than 48 which may not always be the optimal choice. The optimal choice will depend on how much the overhead of a dynamic block caused by having to include the huffman tables is. Zlib builds tables no matter the length and then compares the projected length of a static vs dynamic block which gives a more accurate results (though incurring a little processing overhead instead in the case a block ends up being static.) deflate-rs does something similar. In most cases this won't incur any processing overhead since a dynamic block is used anyhow, so I'm not sure if doing it in the way miniz does is really worth it. Maybe it would even be worth having a simplified code path for compressing very short input if there are use cases where there is a lot of very short data being compressed. Will have to at what the examples results in in code though to see if it's just this, or if there are more things causing issues. |
A potential case for that: Server Send Events |
From rust-lang/flate2-rs#238
The pure rust implementation of deflate gives a somewhat unsatisfactory compression result, even using max compression level.
Somehow, the zlib binding from here is even worse, which is very strange since my benchmark is from Node.js's zlib, using zlib's default compression level.
Consider the following program - it shouldn't be too much of a stretch to wonder how this library isn't able to produce the same result as
COMPRESSED
at default, let alone max.Output
(This was noticed when building https://github.com/Fishrock123/tide-compress.)
The text was updated successfully, but these errors were encountered: