Skip to content
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

Use zopfli instead of flate2 for Gzip compression #112

Merged
merged 3 commits into from
Sep 30, 2023
Merged

Use zopfli instead of flate2 for Gzip compression #112

merged 3 commits into from
Sep 30, 2023

Conversation

AlexTMjugador
Copy link
Contributor

As mentioned in #100, cargo-deb used to use the Zopfli crate for compressing data using the Gzip format, which provides overall smaller results than other general-purpose Gzip encoders that cater to speed more. I think this is a good tradeoff for data meant to be compressed once and distributed or decompressed many times, such as Debian packages.

However, the zopfli crate API did not support the streaming Gzip encoding that cargo-deb moved to. This has changed with its latest v0.8.0 release, bringing it more on par with flate2, so that's no longer a reason to not use Zopfli.

I ran the available test suite and noticed no regressions due to this change.

@kornelski
Copy link
Owner

Cargo deb is also used for one-off deployment, without distribution. Including the --install flag.

This is why it has the --fast flag. Can you re-add support for it? (level() function on the compressor)

@AlexTMjugador
Copy link
Contributor Author

Oh, sure, I was not aware of that, I can add that back! Would you prefer this flag to fall back to flate2, or would it be acceptable to run Zopfli with faster settings, such as fewer iterations or using only static DEFLATE blocks?

@kornelski
Copy link
Owner

It's fine to use zopfli if it can be in the same ballpark as fast zlib.

As mentioned in #100, `cargo-deb` used to use the Zopfli crate for
compressing data using the Gzip format, which provides overall smaller
results than other general-purpose Gzip encoders that cater to speed
more. I think this is a good tradeoff for data meant to be compressed
once and distributed or decompressed many times, such as Debian
packages.

However, the `zopfli` crate API did not support the streaming Gzip
encoding that `cargo-deb` moved to. This has changed with its latest
v0.8.0 release, bringing it more on par with `flate2`, so that's no
longer a reason to not use Zopfli.

I ran the available test suite and noticed no regressions due to this
change.
Zopfli, even when using fast settings, is still quite slow when compared
to `flate2` fast settings, and `gzip` with level 1. Therefore, let's
bring back `flate2` for fast mode.

While at it, let's also tune Zopfli iterations to be less aggressive by
default, which should handle bigger files faster.
@AlexTMjugador
Copy link
Contributor Author

AlexTMjugador commented Sep 29, 2023

Thanks! I did some quick benchmarks and noticed that Zopfli with fast settings is still noticeably slower than gzip/zlib/flate2, so I put flate2 back in when fast mode is enabled to avoid performance regressions in that case.

@kornelski kornelski merged commit 11249e5 into kornelski:main Sep 30, 2023
@kornelski
Copy link
Owner

Thank you

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.

None yet

2 participants