perf(solc): read artifacts in parallel (#1665)
This commit is contained in:
parent
fca8f997fa
commit
4e1462423f
|
@ -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`].
|
||||
///
|
||||
|
|
|
@ -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() {
|
||||
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());
|
||||
artifacts.insert(file_name, entry.read_artifact_files()?);
|
||||
}
|
||||
entry.read_artifact_files().map(|files| (file_name, files))
|
||||
})
|
||||
.collect::<Result<ArtifactsMap<_>>>()?;
|
||||
Ok(Artifacts(artifacts))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue