Skip to content

Conversation

@Hywan
Copy link
Contributor

@Hywan Hywan commented Jan 9, 2026

This patch removes one call to std::mem::take to save two memcpys: JsonRenderer::index can be quite large as noted #142335. self.index can be passed directly to types::Crate. This removal makes self immutable.

The private serialize_and_write method is moved as a function: the self argument is replaced by sess: &Session. This &Session was fetched earlier in after_krate in all cases. This change allows to call serialize_and_write after output_crate is created, without having a conflict around the move of self: the borrow checker is now happy.

I wasn't able to measure the performance impact though because I don't know how to modify rustc-perf as @nnethercote did (sorry).


Follow up of #142335.

r? @nnethercote

This patch removes one call to `std::mem::take` to save two
`memcpy`s: `JsonRenderer::index` can be quite large as noted
rust-lang#142335. `self.index` can be
passed directly to `types::Crate`. This removal makes `self` immutable.

The private `serialize_and_write` method is moved as a function: the
`self` argument is replaced by `sess: &Session`. This `&Session` was
fetched earlier in `after_krate` in all cases. This change allows to
call `serialize_and_write` after `output_crate` is created, without
having a conflict around the move of `self`: the borrow checker is now
happy.
@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Jan 9, 2026
@GuillaumeGomez
Copy link
Member

Looks good to me, thanks! r=me once CI pass

@bors delegate+

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 9, 2026

✌️ @Hywan, you can now approve this pull request!

If @GuillaumeGomez told you to "r=me" after making some further change, then please make that change and post @bors r=GuillaumeGomez.

@Hywan
Copy link
Contributor Author

Hywan commented Jan 9, 2026

@bors r=GuillaumeGomez

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 9, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 9, 2026

📌 Commit b9ae4f7 has been approved by GuillaumeGomez

It is now in the queue for this repository.

@GuillaumeGomez
Copy link
Member

@bors rollup

tgross35 added a commit to tgross35/rust that referenced this pull request Jan 9, 2026
…GuillaumeGomez

rustdoc_json: Remove one call to `std::mem::take` in `after_krate`

This patch removes one call to `std::mem::take` to save two `memcpy`s: `JsonRenderer::index` can be quite large as noted rust-lang#142335. `self.index` can be passed directly to `types::Crate`. This removal makes `self` immutable.

The private `serialize_and_write` method is moved as a function: the `self` argument is replaced by `sess: &Session`. This `&Session` was fetched earlier in `after_krate` in all cases. This change allows to call `serialize_and_write` after `output_crate` is created, without having a conflict around the move of `self`: the borrow checker is now happy.

I wasn't able to measure the performance impact though because I don't know how to modify `rustc-perf` as [@nnethercote  did](rust-lang#142335 (comment)) (sorry).

---

Follow up of rust-lang#142335.

r? @nnethercote
rust-bors bot added a commit that referenced this pull request Jan 10, 2026
Rollup of 11 pull requests

Successful merges:

 - #150269 (Remove inactive nvptx maintainer)
 - #150713 (mgca: Type-check fields of struct expr const args)
 - #150765 (rustc_parse_format: improve error for missing `:` before `?` in format args)
 - #150847 (Fix broken documentation links to SipHash)
 - #150867 (rustdoc_json: Remove one call to `std::mem::take` in `after_krate`)
 - #150872 (Fix some loop block coercion diagnostics)
 - #150874 (Ignore `rustc-src-gpl` in fast try builds)
 - #150875 (Refactor artifact keep mode in bootstrap)
 - #150876 (Mention that `rustc_codegen_gcc` is a subtree in `rustc-dev-guide`)
 - #150882 (Supress unused_parens lint for guard patterns)
 - #150884 (Update bors email in CI postprocessing step)

Failed merges:

 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)

r? @ghost
rust-bors bot added a commit that referenced this pull request Jan 10, 2026
Rollup of 11 pull requests

Successful merges:

 - #150269 (Remove inactive nvptx maintainer)
 - #150713 (mgca: Type-check fields of struct expr const args)
 - #150765 (rustc_parse_format: improve error for missing `:` before `?` in format args)
 - #150847 (Fix broken documentation links to SipHash)
 - #150867 (rustdoc_json: Remove one call to `std::mem::take` in `after_krate`)
 - #150872 (Fix some loop block coercion diagnostics)
 - #150874 (Ignore `rustc-src-gpl` in fast try builds)
 - #150875 (Refactor artifact keep mode in bootstrap)
 - #150876 (Mention that `rustc_codegen_gcc` is a subtree in `rustc-dev-guide`)
 - #150882 (Supress unused_parens lint for guard patterns)
 - #150884 (Update bors email in CI postprocessing step)

Failed merges:

 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)

r? @ghost
@rust-bors rust-bors bot merged commit 68bd262 into rust-lang:main Jan 11, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 11, 2026
rust-timer added a commit that referenced this pull request Jan 11, 2026
Rollup merge of #150867 - chore-librustdoc-json-mem-take, r=GuillaumeGomez

rustdoc_json: Remove one call to `std::mem::take` in `after_krate`

This patch removes one call to `std::mem::take` to save two `memcpy`s: `JsonRenderer::index` can be quite large as noted #142335. `self.index` can be passed directly to `types::Crate`. This removal makes `self` immutable.

The private `serialize_and_write` method is moved as a function: the `self` argument is replaced by `sess: &Session`. This `&Session` was fetched earlier in `after_krate` in all cases. This change allows to call `serialize_and_write` after `output_crate` is created, without having a conflict around the move of `self`: the borrow checker is now happy.

I wasn't able to measure the performance impact though because I don't know how to modify `rustc-perf` as [@nnethercote  did](#142335 (comment)) (sorry).

---

Follow up of #142335.

r? @nnethercote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustdoc-json Area: Rustdoc JSON backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants