-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Don't share id_map
and deref_id_map
#82424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
...and remove `Rc`s for the moved fields. The only shared one that I didn't move was `cache`; see the doc-comment I added to `cache` for details.
It doesn't look like it's shared across threads, so it doesn't need to be thread-safe. Of course, since we're using Rust, we'll get an error if we try to share it across threads, so this should be safe :)
It's cloned a lot, so we don't want it to grow in size unexpectedly.
The size is architecture-dependent.
All the tests passed, so it doesn't seem they need to be shared. Plus they should be item/page-specific. I'm not sure why they were shared before. I think the reason `id_map` worked as a shared value before is that it is cleared before rendering each item (in `render_item`). And then I'm guessing `deref_id_map` worked because it's a hashmap keyed by `DefId`, so there was no overlap (though I'm guessing we could have had issues in the future). Note that `id_map` currently still has to be cleared because otherwise child items would inherit the `id_map` of their parent. I'm hoping to figure out a way to stop cloning `Context`, but until then we have to reset `id_map`.
(rust-highfive has picked a reviewer for you, use r? to override) |
Only the last commit is new (the others will disappear once #82356 is merged and I rebase). |
src/librustdoc/html/render/mod.rs
Outdated
/// The map used to ensure all generated 'id=' attributes are unique. | ||
id_map: RefCell<IdMap>, | ||
/// Tracks section IDs for `Deref` targets so they match in both the main | ||
/// body and the sidebar. | ||
deref_id_map: RefCell<FxHashMap<DefId, String>>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't able to get rid of the RefCells here because the fields are used all over the place.
src/librustdoc/html/render/mod.rs
Outdated
rustc_data_structures::static_assert_size!(Context<'_>, 72); | ||
rustc_data_structures::static_assert_size!(Context<'_>, 152); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Big size increase! Should I box the fields to reduce the size?
Instead of using this new PR, should I just add this commit to #82356? It would reduce the churn of moving the fields back and forth. |
Okay, will do. |
Cherry-picked into #82356. Closing this PR now. |
All the tests passed, so it doesn't seem they need to be shared.
Plus they should be item/page-specific.
I'm not sure why they were shared before. I think the reason
id_map
worked as a shared value before is that it is cleared before rendering
each item (in
render_item
). And then I'm guessingderef_id_map
worked because it's a hashmap keyed by
DefId
, so there was no overlap(though I'm guessing we could have had issues in the future).
Note that
id_map
currently still has to be cleared because otherwisechild items would inherit the
id_map
of their parent. I'm hoping tofigure out a way to stop cloning
Context
, but until then we have toreset
id_map
.Builds on top of #82356 (otherwise we'd have merge conflicts), so this is
blocked on that PR.