diff --git a/CHANGELOG.md b/CHANGELOG.md index f110b0f..cb395d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - The `Header::parse_header` function gained a speed up related to parsing of the binary headers. +- Added `zstdmt` feature which sets zstd compression to use all available cores. ## 0.15.0 diff --git a/Cargo.toml b/Cargo.toml index 308c7fa..dbe49d0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -70,3 +70,5 @@ signature-meta = [] # Segregate tests that require podman to be installed test-with-podman = ["signature-pgp"] + +zstdmt = ["zstd/zstdmt"] diff --git a/src/rpm/compressor.rs b/src/rpm/compressor.rs index b00221f..c8df900 100644 --- a/src/rpm/compressor.rs +++ b/src/rpm/compressor.rs @@ -29,6 +29,8 @@ impl std::str::FromStr for CompressionType { pub enum Compressor { None(Vec), Gzip(flate2::write::GzEncoder>), + /// If the `zstdmt` feature flag is enabled, compression will use all available cores to + /// compress the file. Zstd(zstd::stream::Encoder<'static, Vec>), Xz(xz2::write::XzEncoder>), Bzip2(bzip2::write::BzEncoder>), @@ -43,10 +45,19 @@ impl TryFrom for Compressor { CompressionWithLevel::Gzip(level) => Ok(Compressor::Gzip( flate2::write::GzEncoder::new(Vec::new(), flate2::Compression::new(level)), )), - CompressionWithLevel::Zstd(level) => Ok(Compressor::Zstd(zstd::stream::Encoder::new( - Vec::new(), - level, - )?)), + CompressionWithLevel::Zstd(level) => { + #[cfg_attr(not(feature = "zstdmt"), allow(unused_mut))] + let mut stream = zstd::stream::Encoder::new(Vec::new(), level)?; + + #[cfg(feature = "zstdmt")] + { + let threads = std::thread::available_parallelism()?; + // If someone has more than 2^32 threads, I'm impressed + stream.multithread(threads.get() as u32)?; + } + + Ok(Compressor::Zstd(stream)) + } CompressionWithLevel::Xz(level) => Ok(Compressor::Xz(xz2::write::XzEncoder::new( Vec::new(), level,