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

Added multithreading to zstd compression #689

Merged
merged 3 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Categories Used:

### New Features

- Add multithreading support for `zstd` compression [\#689](https://github.com/ouch-org/ouch/pull/689) ([nalabrie](https://github.com/nalabrie))

### Bug Fixes

- Fix output corrupted on parallel decompression [\#642](https://github.com/ouch-org/ouch/pull/642) ([AntoniosBarotsis](https://github.com/AntoniosBarotsis))
Expand Down
5 changes: 3 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ ignore = "0.4.22"
libc = "0.2.155"
linked-hash-map = "0.5.6"
lz4_flex = "0.11.3"
num_cpus = "1.16.0"
once_cell = "1.19.0"
rayon = "1.10.0"
same-file = "1.0.6"
Expand All @@ -34,7 +35,7 @@ time = { version = "0.3.36", default-features = false }
unrar = { version = "0.5.3", optional = true }
xz2 = "0.1.7"
zip = { version = "0.6.6", default-features = false, features = ["time"] }
zstd = { version = "0.13.1", default-features = false }
zstd = { version = "0.13.2", default-features = false, features = ["zstdmt"]}

[target.'cfg(not(unix))'.dependencies]
is_executable = "1.0.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Output:

| Format | `.tar` | `.zip` | `7z` | `.gz` | `.xz`, `.lzma` | `.bz`, `.bz2` | `.lz4` | `.sz` (Snappy) | `.zst` | `.rar` |
|:---------:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|
| Supported | ✓ | ✓¹ | ✓¹ | ✓² | ✓ | ✓ | ✓ | ✓² | ✓ | ✓³ |
| Supported | ✓ | ✓¹ | ✓¹ | ✓² | ✓ | ✓ | ✓ | ✓² | ✓² | ✓³ |

✓: Supports compression and decompression.

Expand Down
11 changes: 5 additions & 6 deletions src/commands/compress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@ pub fn compress_files(
.from_writer(encoder),
),
Zstd => {
let zstd_encoder = zstd::stream::write::Encoder::new(
let mut zstd_encoder = zstd::stream::write::Encoder::new(
encoder,
level.map_or(zstd::DEFAULT_COMPRESSION_LEVEL, |l| {
(l as i32).clamp(zstd::zstd_safe::min_c_level(), zstd::zstd_safe::max_c_level())
}),
);
// Safety:
// Encoder::new() can only fail if `level` is invalid, but the level
// is `clamp`ed and therefore guaranteed to be valid
Box::new(zstd_encoder.unwrap().auto_finish())
marcospb19 marked this conversation as resolved.
Show resolved Hide resolved
)?;
// Use all available PHYSICAL cores for compression
zstd_encoder.multithread(num_cpus::get_physical() as u32)?;
Box::new(zstd_encoder.auto_finish())
}
Tar | Zip | Rar | SevenZip => unreachable!(),
};
Expand Down