perf(solc): read artifacts in parallel (#1665)

This commit is contained in:
Matthias Seitz 2022-09-05 18:51:50 +02:00 committed by GitHub
parent fca8f997fa
commit 4e1462423f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 7 deletions

View File

@ -563,7 +563,7 @@ where
/// relationship (1-N+). /// relationship (1-N+).
pub trait ArtifactOutput { pub trait ArtifactOutput {
/// Represents the artifact that will be stored for a `Contract` /// 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`]. /// Handle the aggregated set of compiled contracts from the solc [`crate::CompilerOutput`].
/// ///

View File

@ -301,12 +301,19 @@ impl SolFilesCache {
/// let artifacts = cache.read_artifacts::<CompactContractBytecode>().unwrap(); /// let artifacts = cache.read_artifacts::<CompactContractBytecode>().unwrap();
/// # } /// # }
/// ``` /// ```
pub fn read_artifacts<Artifact: DeserializeOwned>(&self) -> Result<Artifacts<Artifact>> { pub fn read_artifacts<Artifact: DeserializeOwned + Send + Sync>(
let mut artifacts = ArtifactsMap::new(); &self,
for (file, entry) in self.files.iter() { ) -> Result<Artifacts<Artifact>> {
let file_name = format!("{}", file.display()); use rayon::prelude::*;
artifacts.insert(file_name, entry.read_artifact_files()?);
} 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::<Result<ArtifactsMap<_>>>()?;
Ok(Artifacts(artifacts)) Ok(Artifacts(artifacts))
} }