-
Notifications
You must be signed in to change notification settings - Fork 13k
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
rustdoc: Cleanup html::render::Context
#82356
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
The key question is whether the testsuite will still pass after this :) |
This comment has been minimized.
This comment has been minimized.
Seems like a bad sign 🤣 |
src/librustdoc/formats/renderer.rs
Outdated
} else if item.name.is_some() { | ||
prof.generic_activity_with_arg("render_item", &*item.name.unwrap_or(unknown).as_str()) | ||
.run(|| cx.item(item))?; | ||
.run(|| format_renderer.item(item))?; | ||
} | ||
} |
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.
Why does the code work this way, where it constantly clones the Context
?
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.
Because some Context
fields are rc
, meaning they're not clone so to speak. ;)
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.
Hm, so maybe a way to clean this up could be to make SharedContext
the only thing that's actually shared?
src/librustdoc/html/render/mod.rs
Outdated
/// The map used to ensure all generated 'id=' attributes are unique. | ||
id_map: Rc<RefCell<IdMap>>, | ||
id_map: RefCell<IdMap>, |
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 think removing the Rc
and Arc
is having much more side-effects that you might expect. :)
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.
Right, I have the same comment as before: this is a change in behavior and should probably be dropped.
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.
@jyn514 Still think so?
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.
The diff is confusing: That change (and comment) is old, but the new change from #82424 prevents it from being "outdated" from GitHub's point of view.
Before I was trying to get rid of the cloning of Context
and get rid of the shared state in Context
, so I removed the Rc and RefCell. Now the code still clones Context
, but all the shared mutable state is moved to SharedContext
, and id_map
isn't shared.
id_map
wasn't shared before, either. Quoting from f8bd38d:
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 (inrender_item
). [...]Note that
id_map
currently still has to be cleared because otherwise
child items would inherit theid_map
of their parent. I'm hoping to
figure out a way to stop cloningContext
, but until then we have to
resetid_map
.
I think this thread can be marked as resolved.
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.
Now the code still clones Context, but all the shared mutable state is moved to SharedContext, and id_map isn't shared.
I don't quite follow - isn't id_map
shared because the same Context
is used everywhere? What do you mean by shared?
Can you link to where Context
is cloned? It still seems like a change in behavior to me since cloning will no longer update the same id_map
in both places.
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.
id_map
is cleared (and was cleared before this change as well) before each item is rendered in render_item
, so it wasn't shared before and it still isn't shared now.
id_map
is cleared/reset here:
And Context
is cloned here:
And here:
And used for after_krate
here:
This will be really hard to get working with all these changes. I'd strongly suggest separating them into separate PRs so you can find what actually caused the test failures. |
Oh err I didn't realize it was a 30 line diff. In that case, maybe just bisect the test failures with git. |
src/librustdoc/html/render/mod.rs
Outdated
/// The map used to ensure all generated 'id=' attributes are unique. | ||
id_map: Rc<RefCell<IdMap>>, | ||
id_map: RefCell<IdMap>, |
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.
Right, I have the same comment as before: this is a change in behavior and should probably be dropped.
My guess is the root issue here is that Context has some fields that are shared and some that are not, despite there also being a SharedContext. |
3204c82
to
7dd6b9f
Compare
This comment has been minimized.
This comment has been minimized.
ec40a39
to
12a886f
Compare
This comment has been minimized.
This comment has been minimized.
Huh, it compiled locally. Is |
@camelid the size is target dependent, you need to add |
Will that work even though the assert is done on the host machine? |
I don't understand the question? The size is dependent on the target, not the host. If you cross compile from x86_64 to x86 I'd expect you to get the same error as on CI. |
Okay, I wasn't sure if |
e471d8d
to
f8bd38d
Compare
I squashed the commits down a bit to remove fixup-esque commits. @GuillaumeGomez ready for review! |
Also create issue for removing shared mutable state.
It's cloned a lot, so we don't want it to grow in size unexpectedly. Only run the assert on x86-64 since 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`.
Reduced from 152 bytes to 88 bytes.
There was no need to clone `id_map` because it was reset before each item was rendered. `deref_id_map` was not reset, but it was keyed by `DefId` and thus was unlikely to have collisions (at least for now). Now we just clone the fields that need to be cloned, and instead create fresh versions of the others.
I don't think the boxing helped performance, in fact I think it potentially made it worse. The data was still being copied, but now it was through a pointer. Thinking about it more, I think boxing might only help when you're passing a big object around by value all the time, rather than the slowdown being that you're cloning it.
Wow, that was the longest and trickiest rebase I've ever done 😅 |
@GuillaumeGomez This is ready for review! You may want to take a look at #82356 (comment) and #82356 (comment). |
Thanks! @bors: r+ |
📌 Commit 5b74097 has been approved by |
⌛ Testing commit 5b74097 with merge 931ff787d37676e7c93bbd127dadd0d9564df501... |
💥 Test timed out |
Seems spurious. @bors retry |
☀️ Test successful - checks-actions |
SharedContext
(except forcache
, whichisn't mutated anyway)
Arc
withRc
Context
id_map
andderef_id_map