Rollup merge of #104797 - weihanglo:stream-write-dwp, r=jackh726

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 🙇🏾‍♂️.
This commit is contained in:
Matthias Krüger 2022-11-25 18:35:40 +01:00 committed by GitHub
commit aec60c6b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -676,8 +676,7 @@ 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)
@ -685,8 +684,10 @@ fn link_dwarf_object<'a>(
.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(())
}) {