diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-02-19 06:45:30 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-19 06:45:30 +0100 |
| commit | 554aea90b8e382678de0e87e07210af19f67f0ab (patch) | |
| tree | 715280de5ddbab0e6fb3947b29838badafe6ac7b | |
| parent | f19adc7acc649ad2b18b6e172b683ebadb3d8a92 (diff) | |
| parent | ae158224acb8a85efce18cd358a445d18c6c6389 (diff) | |
| download | rust-554aea90b8e382678de0e87e07210af19f67f0ab.tar.gz rust-554aea90b8e382678de0e87e07210af19f67f0ab.zip | |
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
| -rw-r--r-- | src/librustdoc/json/mod.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index f9e9fe0d3cf..52980e07b8c 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -8,6 +8,7 @@ mod conversions; use std::cell::RefCell; use std::fs::{create_dir_all, File}; +use std::io::{BufWriter, Write}; use std::path::PathBuf; use std::rc::Rc; @@ -213,7 +214,7 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { let mut index = (*self.index).clone().into_inner(); index.extend(self.get_trait_items()); // This needs to be the default HashMap for compatibility with the public interface for - // rustdoc-json + // rustdoc-json-types #[allow(rustc::default_hash_types)] let output = types::Crate { root: types::Id(String::from("0:0")), @@ -263,8 +264,10 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { let mut p = out_dir; p.push(output.index.get(&output.root).unwrap().name.clone().unwrap()); p.set_extension("json"); - let file = try_err!(File::create(&p), p); - serde_json::ser::to_writer(&file, &output).unwrap(); + let mut file = BufWriter::new(try_err!(File::create(&p), p)); + serde_json::ser::to_writer(&mut file, &output).unwrap(); + try_err!(file.flush(), p); + Ok(()) } |
