From c637a84ad4f4446e6f6bbb1129632b20b42c6e3a Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:14:02 +0100 Subject: [PATCH 1/2] Add finish_ongoing_codegen timer in join_codegen to match cg_llvm --- src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index aba0c28f6b8..19a1de53d1d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -241,6 +241,8 @@ fn join_codegen( sess: &Session, outputs: &OutputFilenames, ) -> (CodegenResults, FxIndexMap) { + let _timer = sess.timer("finish_ongoing_codegen"); + ongoing_codegen.downcast::().unwrap().join( sess, outputs, From 8a0053e9e16586e060612db44578038d3edb107e Mon Sep 17 00:00:00 2001 From: bjorn3 <17426603+bjorn3@users.noreply.github.com> Date: Fri, 8 Nov 2024 16:16:03 +0100 Subject: [PATCH 2/2] Use a BufWriter in emit_module to reduce syscall overhead For the coercions rustc-perf benchmark without this commit reduces the total amount of time it takes to emit the object file from 270ms to 27ms. --- src/driver/aot.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/driver/aot.rs b/src/driver/aot.rs index 419efa90600..8eab73ad5f9 100644 --- a/src/driver/aot.rs +++ b/src/driver/aot.rs @@ -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());