diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-06-10 15:23:11 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2025-06-10 18:14:23 +1000 |
| commit | 195c985398a282aa56befff72b19069a0bf9306d (patch) | |
| tree | d70c7ce23ad93c0a8e378cc8e9bc37a0e024776c | |
| parent | cc671754a308177c2772b5f7e49939180b97d3a4 (diff) | |
| download | rust-195c985398a282aa56befff72b19069a0bf9306d.tar.gz rust-195c985398a282aa56befff72b19069a0bf9306d.zip | |
Avoid cloning `self.index` in `after_krate`.
It can be very big. This reduces peak memory usage for some `--output-format=json` runs by up to 8%.
| -rw-r--r-- | src/librustdoc/json/mod.rs | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/librustdoc/json/mod.rs b/src/librustdoc/json/mod.rs index 180452fa853..db068e0fe39 100644 --- a/src/librustdoc/json/mod.rs +++ b/src/librustdoc/json/mod.rs @@ -294,11 +294,13 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> { unreachable!("RUN_ON_MODULE = false, should never call mod_item_in") } - fn after_krate(self) -> Result<(), Error> { + fn after_krate(mut self) -> Result<(), Error> { debug!("Done with crate"); let e = ExternalCrate { crate_num: LOCAL_CRATE }; - let index = self.index.clone(); + + // We've finished using the index, and don't want to clone it, because it is big. + let index = std::mem::take(&mut self.index); // Note that tcx.rust_target_features is inappropriate here because rustdoc tries to run for // multiple targets: https://github.com/rust-lang/rust/pull/137632 |
