-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
rustc_metadata: Encode list of all crate's traits into metadata #92244
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 41bc5e10f177278a024bc1b82a7c333229fe2546 with merge 9119f3203d18022267eb24170faf67eea61e949c... |
☀️ Try build successful - checks-actions |
Queued 9119f3203d18022267eb24170faf67eea61e949c with parent e6f1f04, future comparison URL. |
Finished benchmarking commit (9119f3203d18022267eb24170faf67eea61e949c): comparison url. Summary: This change led to very large relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. @bors rollup=never |
The perf results are roughly as expected from callgrind runs, I need to cleanup the code. |
This is awesome! I didn't realize it could be cached in the query system, I thought it had to be recalculated since it depends on which crates have been loaded. |
Which part of the changes affects rustdoc's behavior (internal behavior, not user-visible behavior)? I didn't see anything obvious in the diff. |
Rustdoc uses the |
41bc5e1
to
90e3710
Compare
Updated. |
tcx.hir().visit_all_item_likes(&mut visitor); | ||
|
||
let mut all_traits = visitor.traits; |
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.
Can this be implemented using tcx.trait_in_crate(LOCAL_CRATE)
?
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.
There's some performance trade-off here.
From performance point of view all the stuff in fn encode_crate_root
should be encoded by walking the crate once, collecting everything, and then encoding everything, instead of walking the crate many times by LOCAL_CRATE
queries collecting their specific pieces of data.
But the code would certainly be cleaner and with less duplication with the queries.
I can make the refactoring you suggest later in a separate PR, and we'll land it if doesn't cause observable changes in benchmarks.
tcx.hir().visit_all_item_likes(&mut visitor); | ||
|
||
let mut all_traits = visitor.traits; | ||
let mut all_impls: Vec<_> = visitor.impls.into_iter().collect(); |
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.
Pre-existing: same question with tcx.all_trait_implementations(LOCAL_CRATE)
.
📌 Commit 90e3710 has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (78fd0f6): comparison url. Summary: This change led to very large relevant improvements 🎉 in compiler performance.
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
rustc_metadata: Use a query for collecting all traits in encoder Implement refactoring suggested in rust-lang#92244 (comment) r? `@cjgillot`
While working on #88679 I noticed that rustdoc is casually doing something quite expensive, something that is used only for error reporting in rustc - collecting all traits from all crates in the dependency tree.
This PR trades some minor extra time spent by metadata encoder in rustc for major gains for rustdoc (and for rustc runs with errors, which execute the
all_traits
query for better diagnostics).