-
Notifications
You must be signed in to change notification settings - Fork 145
rust: configurable compression level and threads #1394
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
rust: configurable compression level and threads #1394
Conversation
// Enable multithreaded encoding on non-WASM targets. | ||
#[cfg(not(target_arch = "wasm32"))] | ||
enc.set_parameter(zraw::CParameter::NbWorkers(num_cpus::get_physical() as u32))?; | ||
enc.set_parameter(zraw::CParameter::NbWorkers(compression_threads))?; |
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.
A value of 1 means one background thread. Zero disables extra threads entirely. See https://github.com/gyscos/zstd-rs/blob/229054099aa73f7e861762f687d7e07cac1d9b3b/zstd-safe/src/lib.rs#L2228
lz4::EncoderBuilder::new() | ||
.level(compression_level) |
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.
With both lz4 and zstd, level=0
means use the default compression level. References:
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.
Thanks @chriso!
Thanks for the quick review @bennetthardwick! Out of interest, how often is the crate updated? I'm happy to submit a PR to bump the |
That'd be great - I should have asked you to chuck it in this one. We don't have any specific release cycles, we'll just put out a new release as things accumulate. |
Thanks @bennetthardwick. See #1395 |
### Changelog This PR bumps the Rust crate version from `0.18.0` to `0.19.0` ### Docs None ### Description Changes since 0.18.0: * #1394 * #1391 For context, see #1394 (comment)
Changelog
This PR adds two new write options:
compression_level: u32
– compression level to use for zstd/lz4, or zero to use the default compression level.compression_threads: u32
- number of threads to use for compression, or zero to disable multithreaded compression.Docs
None? Let me know if I need to update docs somewhere.
Description
Prior to this PR, it wasn't possible to set the compression level; the default lz4 and zstd compression levels were used. Now, it's possible to set the lz4 and zstd compression levels.
Prior to this PR, non-wasm targets were forced to use multithreaded zstd compression (reference). Now, it's possible to disable multithreaded compression, or to use a different number of compression threads.
lz4 supports multithreaded compression as of v1.10.0 (see [1] and [2]), but this feature doesn't seem to be accessible from the lz4 / lz4-sys crates. For now, the
compression_level
option is ignored when using lz4 compression. Let me know if we should print a warning or fail.I made these write options rather than parameterizing the
Compression
enum variants, because these particular options are orthogonal to the compression algorithm, and because they're only applicable to writers.