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

feat: parallel iterations and sorting using rayon #132

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" ] }
Expand Down
9 changes: 5 additions & 4 deletions src/drivers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::{Path, PathBuf};
use std::time::Duration;
use rayon::prelude::*;

use anyhow::{anyhow, Context};
use log::debug;
Expand All @@ -10,7 +11,7 @@ use crates_io_api::AsyncClient;
use crate::helpers::*;
use crate::PkgFmt;

fn find_version<'a, V: Iterator<Item = &'a str>>(
fn find_version<'a, V: ParallelIterator<Item = &'a str>>(
requirement: &str,
version_iter: V,
) -> Result<String, anyhow::Error> {
Expand Down Expand Up @@ -40,7 +41,7 @@ fn find_version<'a, V: Iterator<Item = &'a str>>(
.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();

Expand Down Expand Up @@ -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 {
Expand All @@ -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!(
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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::<Result<Vec<_>, anyhow::Error>>()?;

Expand Down