Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Commit

Permalink
perf: buffer writes when serializing json
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Aug 11, 2023
1 parent 5145992 commit ce88401
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 4 additions & 1 deletion ethers-solc/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use std::{
hash_map, BTreeSet, HashMap, HashSet,
},
fs::{self},
io::Write,
path::{Path, PathBuf},
time::{Duration, UNIX_EPOCH},
};
Expand Down Expand Up @@ -139,7 +140,9 @@ impl SolFilesCache {
self.len(),
path.display()
);
serde_json::to_writer_pretty(file, self)?;
let mut writer = std::io::BufWriter::with_capacity(1024 * 256, file);
serde_json::to_writer_pretty(&mut writer, self)?;
writer.flush().map_err(|e| SolcError::io(e, path))?;
tracing::trace!("cache file located: \"{}\"", path.display());
Ok(())
}
Expand Down
6 changes: 4 additions & 2 deletions ethers-solc/src/compile/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use semver::{Version, VersionReq};
use serde::{de::DeserializeOwned, Deserialize, Serialize};
use std::{
fmt,
io::BufRead,
io::{BufRead, Write},
path::{Path, PathBuf},
process::{Command, Output, Stdio},
str::FromStr,
Expand Down Expand Up @@ -572,7 +572,9 @@ impl Solc {
.spawn()
.map_err(|err| SolcError::io(err, &self.solc))?;
let stdin = child.stdin.take().expect("Stdin exists.");
serde_json::to_writer(stdin, input)?;
let mut writer = std::io::BufWriter::new(stdin);
serde_json::to_writer(&mut writer, input)?;
writer.flush().map_err(|e| SolcError::io(e, &self.solc))?;
compile_output(child.wait_with_output().map_err(|err| SolcError::io(err, &self.solc))?)
}

Expand Down

0 comments on commit ce88401

Please sign in to comment.