From 57f90fe2099dd936035844b8f2ed350018141c94 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Fri, 11 Aug 2023 15:59:08 +0200 Subject: [PATCH] perf: buffer writes when serializing json --- ethers-solc/src/cache.rs | 5 ++++- ethers-solc/src/compile/mod.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/ethers-solc/src/cache.rs b/ethers-solc/src/cache.rs index a239f0f0f2..f87ca8ea99 100644 --- a/ethers-solc/src/cache.rs +++ b/ethers-solc/src/cache.rs @@ -16,6 +16,7 @@ use std::{ hash_map, BTreeSet, HashMap, HashSet, }, fs::{self}, + io::Write, path::{Path, PathBuf}, time::{Duration, UNIX_EPOCH}, }; @@ -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(()) } diff --git a/ethers-solc/src/compile/mod.rs b/ethers-solc/src/compile/mod.rs index 3eaa11cb2e..38f46e058d 100644 --- a/ethers-solc/src/compile/mod.rs +++ b/ethers-solc/src/compile/mod.rs @@ -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,