Merge pull request #1541 from rust-lang/perf_opts

Use a BufWriter in emit_module to reduce syscall overhead
This commit is contained in:
bjorn3 2024-11-09 12:14:06 +01:00 committed by GitHub
commit e9ac680447
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -2,6 +2,7 @@
//! standalone executable.
use std::fs::{self, File};
use std::io::BufWriter;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::thread::JoinHandle;
@ -397,14 +398,19 @@ fn emit_module(
}
let tmp_file = output_filenames.temp_path(OutputType::Object, Some(&name));
let mut file = match File::create(&tmp_file) {
let file = match File::create(&tmp_file) {
Ok(file) => file,
Err(err) => return Err(format!("error creating object file: {}", err)),
};
let mut file = BufWriter::new(file);
if let Err(err) = object.write_stream(&mut file) {
return Err(format!("error writing object file: {}", err));
}
let file = match file.into_inner() {
Ok(file) => file,
Err(err) => return Err(format!("error writing object file: {}", err)),
};
prof.artifact_size("object_file", &*name, file.metadata().unwrap().len());

View File

@ -241,6 +241,8 @@ fn join_codegen(
sess: &Session,
outputs: &OutputFilenames,
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
let _timer = sess.timer("finish_ongoing_codegen");
ongoing_codegen.downcast::<driver::aot::OngoingCodegen>().unwrap().join(
sess,
outputs,