From 4e1462423f433e78fe6c5efef839324c53d18d52 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Mon, 5 Sep 2022 18:51:50 +0200 Subject: [PATCH] perf(solc): read artifacts in parallel (#1665) --- ethers-solc/src/artifact_output/mod.rs | 2 +- ethers-solc/src/cache.rs | 19 +++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/ethers-solc/src/artifact_output/mod.rs b/ethers-solc/src/artifact_output/mod.rs index 37528dc1..d5e23367 100644 --- a/ethers-solc/src/artifact_output/mod.rs +++ b/ethers-solc/src/artifact_output/mod.rs @@ -563,7 +563,7 @@ where /// relationship (1-N+). pub trait ArtifactOutput { /// Represents the artifact that will be stored for a `Contract` - type Artifact: Artifact + DeserializeOwned + Serialize + fmt::Debug; + type Artifact: Artifact + DeserializeOwned + Serialize + fmt::Debug + Send + Sync; /// Handle the aggregated set of compiled contracts from the solc [`crate::CompilerOutput`]. /// diff --git a/ethers-solc/src/cache.rs b/ethers-solc/src/cache.rs index 4943b69f..0a335fa9 100644 --- a/ethers-solc/src/cache.rs +++ b/ethers-solc/src/cache.rs @@ -301,12 +301,19 @@ impl SolFilesCache { /// let artifacts = cache.read_artifacts::().unwrap(); /// # } /// ``` - pub fn read_artifacts(&self) -> Result> { - let mut artifacts = ArtifactsMap::new(); - for (file, entry) in self.files.iter() { - let file_name = format!("{}", file.display()); - artifacts.insert(file_name, entry.read_artifact_files()?); - } + pub fn read_artifacts( + &self, + ) -> Result> { + use rayon::prelude::*; + + let artifacts = self + .files + .par_iter() + .map(|(file, entry)| { + let file_name = format!("{}", file.display()); + entry.read_artifact_files().map(|files| (file_name, files)) + }) + .collect::>>()?; Ok(Artifacts(artifacts)) }