Skip to content

Commit 554aea9

Browse files
authored
Rollup merge of #93954 - aDotInTheVoid:json-buffer, r=Mark-Simulacrum
rustdoc-json: buffer output It turns out we were doing syscalls for each part of the json syntax Before: ``` ... [pid 1801267] write(5, "\"", 1) = 1 [pid 1801267] write(5, ",", 1) = 1 [pid 1801267] write(5, "\"", 1) = 1 ... ``` After: ``` [pid 1974821] write(5, "{\"root\":\"0:0\",\"crate_version\":nu"..., 1575) = 1575 ``` In one benchmark (one struct, almost all time in `std`), this gives ~2x perf r? `@CraftSpider` `@rustbot` modify labels: +A-rustdoc-json +T-rustdoc -A-testsuite
2 parents f19adc7 + ae15822 commit 554aea9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/librustdoc/json/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ mod conversions;
88

99
use std::cell::RefCell;
1010
use std::fs::{create_dir_all, File};
11+
use std::io::{BufWriter, Write};
1112
use std::path::PathBuf;
1213
use std::rc::Rc;
1314

@@ -213,7 +214,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
213214
let mut index = (*self.index).clone().into_inner();
214215
index.extend(self.get_trait_items());
215216
// This needs to be the default HashMap for compatibility with the public interface for
216-
// rustdoc-json
217+
// rustdoc-json-types
217218
#[allow(rustc::default_hash_types)]
218219
let output = types::Crate {
219220
root: types::Id(String::from("0:0")),
@@ -263,8 +264,10 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
263264
let mut p = out_dir;
264265
p.push(output.index.get(&output.root).unwrap().name.clone().unwrap());
265266
p.set_extension("json");
266-
let file = try_err!(File::create(&p), p);
267-
serde_json::ser::to_writer(&file, &output).unwrap();
267+
let mut file = BufWriter::new(try_err!(File::create(&p), p));
268+
serde_json::ser::to_writer(&mut file, &output).unwrap();
269+
try_err!(file.flush(), p);
270+
268271
Ok(())
269272
}
270273

0 commit comments

Comments
 (0)