Skip to content

Commit c9c4e29

Browse files
Update decoding to stream into a single pre-allocated buffer
1 parent db16038 commit c9c4e29

File tree

4 files changed

+28
-19
lines changed

4 files changed

+28
-19
lines changed

Cargo.lock

Lines changed: 8 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

collector/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ impl Ord for Commit {
162162
pub struct Patch {
163163
index: usize,
164164
pub name: PatchName,
165-
path: PathBuf,
165+
path: PatchPath,
166166
}
167167

168168
crate::intern!(pub struct PatchName);
169+
crate::intern!(pub struct PatchPath);
169170

170171
impl PartialEq for Patch {
171172
fn eq(&self, other: &Self) -> bool {
@@ -207,7 +208,7 @@ impl Patch {
207208
};
208209

209210
Patch {
210-
path: PathBuf::from(path.file_name().unwrap()),
211+
path: PatchPath::from(path.file_name().unwrap().to_str().unwrap()),
211212
index,
212213
name: name.as_str().into(),
213214
}
@@ -216,7 +217,7 @@ impl Patch {
216217
pub fn apply(&self, dir: &Path) -> Result<(), String> {
217218
log::debug!("applying {} to {:?}", self.name, dir);
218219
let mut cmd = process::Command::new("patch");
219-
cmd.current_dir(dir).args(&["-Np1", "-i"]).arg(&self.path);
220+
cmd.current_dir(dir).args(&["-Np1", "-i"]).arg(&*self.path);
220221
cmd.stdout(Stdio::null());
221222
if cmd.status().map(|s| !s.success()).unwrap_or(false) {
222223
return Err(format!("could not execute {:?}.", cmd));
@@ -269,7 +270,7 @@ impl BenchmarkState {
269270
match &mut self {
270271
BenchmarkState::IncrementalPatched(patch) => {
271272
patch.index = 0;
272-
patch.path = PathBuf::new();
273+
patch.path = PatchPath::from("");
273274
}
274275
_ => {}
275276
}

site/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jemallocator = "0.3"
3030
jemalloc-ctl = "0.3"
3131
rust_team_data = { git = "https://github.com/rust-lang/team" }
3232
parking_lot = "0.10"
33-
snap = "0.2.5"
33+
snap = "1"
3434
rustc-artifacts = "0.1.1"
3535

3636
[dependencies.collector]

site/src/load.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use std::collections::{BTreeSet, HashMap, HashSet};
1111
use std::env;
1212
use std::fs;
13+
use std::io::Read;
1314
use std::path::{Path, PathBuf};
1415
use std::sync::Arc;
1516

@@ -216,27 +217,27 @@ impl InputData {
216217

217218
// Read all files from repo_loc/processed
218219
let latest_section_start = ::std::time::Instant::now();
220+
let mut file_contents = Vec::new();
219221
for entry in fs::read_dir(repo_loc.join("times"))? {
220222
let entry = entry?;
221223
if entry.file_type()?.is_dir() {
222224
continue;
223225
}
224226
let filename = entry.file_name();
225227
let filename = filename.to_str().unwrap();
226-
let file_contents =
227-
fs::read(entry.path()).with_context(|| format!("Failed to read {}", filename))?;
228-
let c;
229-
let file_contents = if filename.ends_with(".sz") {
230-
use std::io::Read;
231-
let mut out =
232-
String::with_capacity(snap::decompress_len(&file_contents).unwrap_or(0));
233-
let mut szip_reader = snap::Reader::new(&file_contents[..]);
234-
szip_reader.read_to_string(&mut out).unwrap();
235-
c = out;
236-
c.as_str()
228+
let mut file = fs::File::open(entry.path())
229+
.with_context(|| format!("Failed to open {}", entry.path().display()))?;
230+
file_contents.truncate(0);
231+
if filename.ends_with(".sz") {
232+
let mut szip_reader = snap::read::FrameDecoder::new(std::io::BufReader::new(file));
233+
szip_reader
234+
.read_to_end(&mut file_contents)
235+
.with_context(|| format!("Failed to read {}", entry.path().display()))?;
237236
} else {
238-
std::str::from_utf8(&file_contents).unwrap()
237+
file.read_to_end(&mut file_contents)
238+
.with_context(|| format!("Failed to read {}", entry.path().display()))?;
239239
};
240+
let file_contents = std::str::from_utf8(&file_contents).unwrap();
240241

241242
if filename.starts_with("artifact-") {
242243
let contents: ArtifactData = match serde_json::from_str(&file_contents) {
@@ -270,6 +271,7 @@ impl InputData {
270271
}
271272
}
272273
}
274+
std::mem::drop(file_contents);
273275

274276
info!(
275277
"{} commits/artifacts loaded in {:?}",

0 commit comments

Comments
 (0)