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+).
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`].
///

View File

@ -301,12 +301,19 @@ impl SolFilesCache {
/// let artifacts = cache.read_artifacts::<CompactContractBytecode>().unwrap();
/// # }
/// ```
pub fn read_artifacts<Artifact: DeserializeOwned>(&self) -> Result<Artifacts<Artifact>> {
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<Artifact: DeserializeOwned + Send + Sync>(
&self,
) -> Result<Artifacts<Artifact>> {
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::<Result<ArtifactsMap<_>>>()?;
Ok(Artifacts(artifacts))
}