Don't share id_map and deref_id_map#82424
Closed
camelid wants to merge 7 commits intorust-lang:masterfrom
Closed
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`.
Contributor
|
(rust-highfive has picked a reviewer for you, use r? to override) |
Member
Author
|
Only the last commit is new (the others will disappear once #82356 is merged and I rebase). |
camelid
commented
Feb 23, 2021
Comment on lines
113
to
117
| /// 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>>, |
Member
Author
There was a problem hiding this comment.
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
Comment on lines
133
to
138
| rustc_data_structures::static_assert_size!(Context<'_>, 72); | ||
| rustc_data_structures::static_assert_size!(Context<'_>, 152); |
Member
Author
There was a problem hiding this comment.
Big size increase! Should I box the fields to reduce the size?
Member
Author
|
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. |
Member
Member
Author
|
Okay, will do. |
Member
Author
|
Cherry-picked into #82356. Closing this PR now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_mapworked as a shared value before is that it is cleared before rendering
each item (in
render_item). And then I'm guessingderef_id_mapworked 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_mapcurrently still has to be cleared because otherwisechild items would inherit the
id_mapof 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.