Skip to content

Commit e6c07b3

Browse files
committed
Use a BufWriter in emit_module
For the coercions rustc-perf benchmark without this writing the object file takes 265ms while codegen only takes 40ms. The huge amount of time to write the object file is likely because of syscall overhead.
1 parent c637a84 commit e6c07b3

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/driver/aot.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//! standalone executable.
33
44
use std::fs::{self, File};
5+
use std::io::BufWriter;
56
use std::path::{Path, PathBuf};
67
use std::sync::Arc;
78
use std::thread::JoinHandle;
@@ -397,14 +398,19 @@ fn emit_module(
397398
}
398399

399400
let tmp_file = output_filenames.temp_path(OutputType::Object, Some(&name));
400-
let mut file = match File::create(&tmp_file) {
401+
let file = match File::create(&tmp_file) {
401402
Ok(file) => file,
402403
Err(err) => return Err(format!("error creating object file: {}", err)),
403404
};
404405

406+
let mut file = BufWriter::new(file);
405407
if let Err(err) = object.write_stream(&mut file) {
406408
return Err(format!("error writing object file: {}", err));
407409
}
410+
let file = match file.into_inner() {
411+
Ok(file) => file,
412+
Err(err) => return Err(format!("error writing object file: {}", err)),
413+
};
408414

409415
prof.artifact_size("object_file", &*name, file.metadata().unwrap().len());
410416

0 commit comments

Comments
 (0)