From 23e33412a4f49ff2473c1fb70ff9aa7f9033182b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Vin=C3=ADcius=20R=2E=20Miguel?= Date: Thu, 5 Jan 2023 21:15:12 -0300 Subject: [PATCH] Decompress files in parallel --- Cargo.lock | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/commands/mod.rs | 27 +++++++++++------- 3 files changed, 99 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10b07a7..b2dd25d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -209,6 +209,40 @@ dependencies = [ ] [[package]] +name = "crossbeam-channel" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +dependencies = [ + "cfg-if", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-deque" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" +dependencies = [ + "cfg-if", + "crossbeam-epoch", + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.9.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" +dependencies = [ + "autocfg", + "cfg-if", + "crossbeam-utils", + "memoffset", + "scopeguard", +] + +[[package]] name = "crossbeam-utils" version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -510,6 +544,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] +name = "memoffset" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" +dependencies = [ + "autocfg", +] + +[[package]] name = "miniz_oxide" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -528,6 +571,16 @@ dependencies = [ ] [[package]] +name = "num_cpus" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +dependencies = [ + "hermit-abi 0.2.6", + "libc", +] + +[[package]] name = "once_cell" version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -563,6 +616,7 @@ dependencies = [ "parse-display", "proptest", "rand", + "rayon", "same-file", "snap", "tar", @@ -755,6 +809,28 @@ dependencies = [ ] [[package]] +name = "rayon" +version = "1.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" +dependencies = [ + "either", + "rayon-core", +] + +[[package]] +name = "rayon-core" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" +dependencies = [ + "crossbeam-channel", + "crossbeam-deque", + "crossbeam-utils", + "num_cpus", +] + +[[package]] name = "redox_syscall" version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -837,6 +913,12 @@ dependencies = [ ] [[package]] +name = "scopeguard" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" + +[[package]] name = "serde" version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml index 3ef8fa0..a30ef70 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ libc = "0.2.139" linked-hash-map = "0.5.6" lzzzz = "1.0.4" once_cell = "1.17.0" +rayon = "1.6.1" same-file = "1.0.6" snap = "1.1.0" tar = "0.4.38" diff --git a/src/commands/mod.rs b/src/commands/mod.rs index d893e61..f097733 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -9,6 +9,7 @@ use std::{ path::{Path, PathBuf}, }; +use rayon::prelude::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator}; use utils::colors; use crate::{ @@ -272,17 +273,21 @@ pub fn run( PathBuf::from(".") }; - for ((input_path, formats), file_name) in files.iter().zip(formats).zip(output_paths) { - let output_file_path = output_dir.join(file_name); // Path used by single file format archives - decompress_file( - input_path, - formats, - &output_dir, - output_file_path, - question_policy, - args.quiet, - )?; - } + files + .par_iter() + .zip(formats) + .zip(output_paths) + .try_for_each(|((input_path, formats), file_name)| { + let output_file_path = output_dir.join(file_name); // Path used by single file format archives + decompress_file( + input_path, + formats, + &output_dir, + output_file_path, + question_policy, + args.quiet, + ) + })?; } Subcommand::List { archives: files, tree } => { let mut formats = vec![]; -- 2.11.4.GIT