Skip to content

Commit

Permalink
Rollup merge of #104797 - weihanglo:stream-write-dwp, r=jackh726
Browse files Browse the repository at this point in the history
rustc_codegen_ssa: write `.dwp` in a streaming fashion

When writing a `.dwp` file, rustc writes to a Vec first then to a BufWriter-wrapped file. It seems very likely that we can write in a streaming fashion to avoid double buffering in an intermediate Vec.

On my Linux machine, `.dwp` from the latest rust-lang/cargo is 113MiB. It may worth a stream writer, though I didn't do any benchmark 🙇🏾‍♂️.
  • Loading branch information
matthiaskrgr authored Nov 25, 2022
2 parents 8f3f498 + 433d471 commit aec60c6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,17 +676,18 @@ fn link_dwarf_object<'a>(
thorin::MissingReferencedObjectBehaviour::Skip,
)?;

let output = package.finish()?.write()?;
let mut output_stream = BufWriter::new(
let output_stream = BufWriter::new(
OpenOptions::new()
.read(true)
.write(true)
.create(true)
.truncate(true)
.open(dwp_out_filename)?,
);
output_stream.write_all(&output)?;
output_stream.flush()?;
let mut output_stream = object::write::StreamingBuffer::new(output_stream);
package.finish()?.emit(&mut output_stream)?;
output_stream.result()?;
output_stream.into_inner().flush()?;

Ok(())
}) {
Expand Down

0 comments on commit aec60c6

Please sign in to comment.