Skip to content

Commit

Permalink
Auto merge of #69227 - Marwes:buffer_stderr, r=varkor
Browse files Browse the repository at this point in the history
perf: Buffer stderr when writing json errors/warnings

Since `stderr` is unbuffered, writing out json messages actually take up
about ~10%/0.1s of the runtime of the `inflate` benchmark as it generates a fair number of warnings.

cc #64413
  • Loading branch information
bors committed Feb 29, 2020
2 parents 55aee8d + ee064be commit 04e7f96
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/librustc_errors/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl JsonEmitter {
macro_backtrace: bool,
) -> JsonEmitter {
JsonEmitter {
dst: Box::new(io::stderr()),
dst: Box::new(io::BufWriter::new(io::stderr())),
registry,
sm: source_map,
pretty,
Expand Down Expand Up @@ -104,7 +104,8 @@ impl Emitter for JsonEmitter {
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
} else {
writeln!(&mut self.dst, "{}", as_json(&data))
};
}
.and_then(|_| self.dst.flush());
if let Err(e) = result {
panic!("failed to print diagnostics: {:?}", e);
}
Expand All @@ -116,7 +117,8 @@ impl Emitter for JsonEmitter {
writeln!(&mut self.dst, "{}", as_pretty_json(&data))
} else {
writeln!(&mut self.dst, "{}", as_json(&data))
};
}
.and_then(|_| self.dst.flush());
if let Err(e) = result {
panic!("failed to print notification: {:?}", e);
}
Expand Down

0 comments on commit 04e7f96

Please sign in to comment.