-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[perf] GenericArgs
-related: Change asserts to debug asserts & use more slice interning over iterable interning
#142289
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
|
||
pub mod tls; | ||
|
||
use std::assert_matches::{assert_matches, debug_assert_matches}; | ||
use std::assert_matches::debug_assert_matches; | ||
use std::borrow::Borrow; | ||
use std::cmp::Ordering; | ||
use std::env::VarError; | ||
|
@@ -268,9 +268,9 @@ impl<'tcx> Interner for TyCtxt<'tcx> { | |
def_id: DefId, | ||
args: ty::GenericArgsRef<'tcx>, | ||
) -> (ty::TraitRef<'tcx>, &'tcx [ty::GenericArg<'tcx>]) { | ||
assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst); | ||
debug_assert_matches!(self.def_kind(def_id), DefKind::AssocTy | DefKind::AssocConst); | ||
let trait_def_id = self.parent(def_id); | ||
assert_matches!(self.def_kind(trait_def_id), DefKind::Trait); | ||
debug_assert_matches!(self.def_kind(trait_def_id), DefKind::Trait); | ||
Comment on lines
+271
to
+273
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The main and most relevant positive perf impact comes from changing these asserts to debug ones. Results: #142289 (comment). |
||
let trait_generics = self.generics_of(trait_def_id); | ||
( | ||
ty::TraitRef::new_from_args(self, trait_def_id, args.truncate_to(self, trait_generics)), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -588,7 +588,7 @@ impl<'tcx> GenericArgs<'tcx> { | |
} | ||
|
||
pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> GenericArgsRef<'tcx> { | ||
tcx.mk_args_from_iter(self.iter().take(generics.count())) | ||
tcx.mk_args(&self[..generics.count()]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one wasn't tested in isolation (three perf runs are already a lot (I had to narrow down what is and what isn't perf relevant)) but I presume it to be helping since slicing & slice interning should generally be faster than iterating & "iterable interning" and this function is semi hot / lukewarm I'm pretty sure. The first approach (which contains this change) yielded more improvements (results: #142289 (comment) (e.g., for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could rerun perf for this change / commit only (which seems a bit overkill) or just drop it entirely? WDYT? |
||
} | ||
|
||
pub fn print_as_list(&self) -> 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.
Just a drive-by change, definitely not relevant or hot.