diff --git a/Cargo.lock b/Cargo.lock index e1fffb574..eae814aa3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -161,6 +161,7 @@ dependencies = [ "env_logger", "flate2", "log", + "rayon", "reqwest", "semver", "serde", diff --git a/Cargo.toml b/Cargo.toml index 70bd46b5e..85fdff522 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,6 +28,7 @@ crates_io_api = { version = "0.8.0", default-features = false, features = ["rust dirs = "4.0.0" flate2 = "1.0.22" log = "0.4.14" +rayon = "1.5.2" reqwest = { version = "0.11.10", features = [ "rustls-tls" ], default-features = false } semver = "1.0.7" serde = { version = "1.0.136", features = [ "derive" ] } diff --git a/src/drivers.rs b/src/drivers.rs index d39525d1b..72f0e0dc6 100644 --- a/src/drivers.rs +++ b/src/drivers.rs @@ -1,5 +1,6 @@ use std::path::{Path, PathBuf}; use std::time::Duration; +use rayon::prelude::*; use anyhow::{anyhow, Context}; use log::debug; @@ -10,7 +11,7 @@ use crates_io_api::AsyncClient; use crate::helpers::*; use crate::PkgFmt; -fn find_version<'a, V: Iterator>( +fn find_version<'a, V: ParallelIterator>( requirement: &str, version_iter: V, ) -> Result { @@ -40,7 +41,7 @@ fn find_version<'a, V: Iterator>( .collect(); // Sort by highest matching version - filtered.sort_by(|a, b| { + filtered.par_sort_by(|a, b| { let a = Version::parse(a).unwrap(); let b = Version::parse(b).unwrap(); @@ -83,7 +84,7 @@ pub async fn fetch_crate_cratesio( }; // Locate matching version - let version_iter = base_info.versions().iter().filter_map(|v| { + let version_iter = base_info.versions().par_iter().filter_map(|v| { if !v.is_yanked() { Some(v.version()) } else { @@ -105,7 +106,7 @@ pub async fn fetch_crate_cratesio( .context("Error fetching crate information")?; // Fetch information for the filtered version - let version = match crate_info.versions.iter().find(|v| v.num == version_name) { + let version = match crate_info.versions.par_iter().find_first(|v| v.num == version_name) { Some(v) => v, None => { return Err(anyhow::anyhow!( diff --git a/src/main.rs b/src/main.rs index 3ec690685..b4b274d7b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,7 @@ use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode}; use structopt::StructOpt; use tempdir::TempDir; use tokio::process::Command; +use rayon::prelude::*; use cargo_binstall::{ bins, @@ -275,7 +276,7 @@ async fn install_from_package( }; let bin_files = binaries - .iter() + .par_iter() .map(|p| bins::BinFile::from_product(&bin_data, p)) .collect::, anyhow::Error>>()?;