about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2022-11-25 18:35:40 +0100
committerGitHub <noreply@github.com>2022-11-25 18:35:40 +0100
commitaec60c6b7cc511979b176f9935b9f9d7c807ecd2 (patch)
tree85b4ce8626f991cf10c7793f8b768de49e62e8c1
parent8f3f4980b4c9cf7b062b2c7638070e256381114f (diff)
parent433d471a1a06b5852c7f6b5d276725933d8ddce6 (diff)
downloadrust-aec60c6b7cc511979b176f9935b9f9d7c807ecd2.tar.gz
rust-aec60c6b7cc511979b176f9935b9f9d7c807ecd2.zip
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 🙇🏾‍♂️.
-rw-r--r--compiler/rustc_codegen_ssa/src/back/link.rs9
1 files changed, 5 insertions, 4 deletions
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
index 2091730af22..762430c6187 100644
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
@@ -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(())
     }) {