perf(solc): read artifacts in parallel (#1665)
This commit is contained in:
parent
fca8f997fa
commit
4e1462423f
|
@ -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`].
|
||||||
///
|
///
|
||||||
|
|
|
@ -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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue