Skip to content

Commit 195c985

Browse files
committed
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%.
1 parent cc67175 commit 195c985

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/librustdoc/json/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,11 +294,13 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
294294
unreachable!("RUN_ON_MODULE = false, should never call mod_item_in")
295295
}
296296

297-
fn after_krate(self) -> Result<(), Error> {
297+
fn after_krate(mut self) -> Result<(), Error> {
298298
debug!("Done with crate");
299299

300300
let e = ExternalCrate { crate_num: LOCAL_CRATE };
301-
let index = self.index.clone();
301+
302+
// We've finished using the index, and don't want to clone it, because it is big.
303+
let index = std::mem::take(&mut self.index);
302304

303305
// Note that tcx.rust_target_features is inappropriate here because rustdoc tries to run for
304306
// multiple targets: https://github.com/rust-lang/rust/pull/137632

0 commit comments

Comments
 (0)