-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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: track the simplified Self type for every trait impl. #75008
Conversation
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit 6bf3a4b with merge 128201b46cdfa059217962ae2f159583e0ae5f93... |
cc @jyn514 as well, you were asking about something similar recently |
☀️ Try build successful - checks-actions, checks-azure |
Queued 128201b46cdfa059217962ae2f159583e0ae5f93 with parent dfe1e3b, future comparison URL. |
This isn't quite what I was looking for ... this is making existing queries more efficient wrt metadata on disk, while #74489 is adding a new query so that looking up the traits for a type is less expensive. This looks good in and of itself though :) |
Finished benchmarking try commit (128201b46cdfa059217962ae2f159583e0ae5f93): comparison url. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. Please note that if the perf results are neutral, you should likely undo the rollup=never given below by specifying Importantly, though, if the results of this run are non-neutral do not roll this PR up -- it will mask other regressions or improvements in the roll up. @bors rollup=never |
I'm very suspicious of the decrease in |
@@ -187,32 +187,38 @@ pub(super) fn all_local_trait_impls<'tcx>( | |||
pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> TraitImpls { | |||
let mut impls = TraitImpls::default(); | |||
|
|||
{ | |||
let mut add_impl = |impl_def_id: DefId| { | |||
let impl_self_ty = tcx.type_of(impl_def_id); |
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.
so is the performance improvement here just that we don't have to compute type_of
and then simplify the type, but instead we do it "up front" when encoding?
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 think all the cost is in decoding the Ty
from type_of
(simplification should be relatively cheap).
And based on the detailed query profiling info, I'm guessing it's ty::Adt
containing a &'tcx ty::AdtDef
instead of just a DefId
, and somehow item_attrs
getting called for every struct
/enum
/union
implementing the trait (in order to create the ty::AdtDef
?).
I'm suspecting this is similar to what @nnethercote was talking about a few months ago, where the deserialization of doc comment attributes was a significant cost (I don't recall what happened with that line of investigation though).
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.
#65750 introduced a specialized representation for doc comments, that might be what you are referring to.
@bors r+ rollup=never |
📌 Commit 6bf3a4b has been approved by |
⌛ Testing commit 6bf3a4b with merge b1bc5c61f41b461d5976940b18d09dd316a57027... |
💥 Test timed out |
@bors retry |
☀️ Test successful - checks-actions, checks-azure |
Final perf result: https://perf.rust-lang.org/compare.html?start=22ee68dc586440f96b76b32fbd6087507c6afdb9&end=3cfc7fe78eccc754b16981704a098d7bd520e2fd&stat=instructions:u Gimli regression with this PR applied: https://perf.rust-lang.org/compare.html?start=cfc572cae2d1fc381cce476b5c787fd7221af98c&end=3cfc7fe78eccc754b16981704a098d7bd520e2fd&stat=instructions%3Au |
That's somewhat expected, it's hard to tell what the actual wins are from relative measurements, because the delta is absolute across the board (not exactly a startup cost, but very similar for any one given trait). I mostly went on the basis of @Mark-Simulacrum finding out that a lot of the cost was in |
For the
traits_impls_of
query, we index the impls byfast_reject::SimplifiedType
(a "shallow type"), which allows some simple cases likeimpl Trait<..> for Foo<..>
to be efficiently iterated over, by e.g.for_each_relevant_impl
.This PR encodes the
fast_reject::SimplifiedType
cross-crate to avoid needing to deserialize theSelf
type of everyimpl
in order to simplify it - the simplification itself should be cheap, but the deserialization is less so.We could go further from here and make loading the list of impls lazy, for a given simplified
Self
type, but that would have more complicated implications for performance, and this PR doesn't do anything in that regard.r? @nikomatsakis cc @Mark-Simulacrum