Skip to content

Commit aec60c6

Browse files
authored
Rollup merge of rust-lang#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 🙇🏾‍♂️.
2 parents 8f3f498 + 433d471 commit aec60c6

File tree

1 file changed

+5
-4
lines changed
  • compiler/rustc_codegen_ssa/src/back

1 file changed

+5
-4
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -676,17 +676,18 @@ fn link_dwarf_object<'a>(
676676
thorin::MissingReferencedObjectBehaviour::Skip,
677677
)?;
678678

679-
let output = package.finish()?.write()?;
680-
let mut output_stream = BufWriter::new(
679+
let output_stream = BufWriter::new(
681680
OpenOptions::new()
682681
.read(true)
683682
.write(true)
684683
.create(true)
685684
.truncate(true)
686685
.open(dwp_out_filename)?,
687686
);
688-
output_stream.write_all(&output)?;
689-
output_stream.flush()?;
687+
let mut output_stream = object::write::StreamingBuffer::new(output_stream);
688+
package.finish()?.emit(&mut output_stream)?;
689+
output_stream.result()?;
690+
output_stream.into_inner().flush()?;
690691

691692
Ok(())
692693
}) {

0 commit comments

Comments
 (0)