Skip to content

Commit

Permalink
Auto merge of rust-lang#134866 - osiewicz:write-rlib-bufwriter, r=bjorn3
Browse files Browse the repository at this point in the history
rustc_codegen_ssa: Buffer file writes in link_rlib

This makes this step take ~25ms on my machine (M3 Max 64GB) for Zed repo instead of ~150ms (on editor crate). Additionally it takes down the time needed for a clean cargo build of ripgrep from ~6.1s to 5.9s.

This change is mostly relevant for dev builds of crates with multiple large CGUs.
I imagine it could be quite relevant for dev scenarios on Windows, but sadly I have no way to measure that myself.
  • Loading branch information
bors committed Dec 30, 2024
2 parents 8cdc67e + 586a805 commit 84e9308
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions compiler/rustc_codegen_ssa/src/back/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::env;
use std::error::Error;
use std::ffi::OsString;
use std::fs::{self, File};
use std::io::{self, Write};
use std::io::{self, BufWriter, Write};
use std::path::{Path, PathBuf};

use ar_archive_writer::{
Expand Down Expand Up @@ -509,16 +509,19 @@ impl<'a> ArArchiveBuilder<'a> {
io_error_context("couldn't create a directory for the temp file", err)
})?;
let archive_tmpfile_path = archive_tmpdir.path().join("tmp.a");
let mut archive_tmpfile = File::create_new(&archive_tmpfile_path)
let archive_tmpfile = File::create_new(&archive_tmpfile_path)
.map_err(|err| io_error_context("couldn't create the temp file", err))?;

let mut archive_tmpfile = BufWriter::new(archive_tmpfile);
write_archive_to_stream(
&mut archive_tmpfile,
&entries,
archive_kind,
false,
/* is_ec = */ self.sess.target.arch == "arm64ec",
)?;
archive_tmpfile.flush()?;
drop(archive_tmpfile);

let any_entries = !entries.is_empty();
drop(entries);
Expand Down

0 comments on commit 84e9308

Please sign in to comment.