-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Feat: added caching schema for debuginfo type names #88898
Conversation
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@@ -106,6 +106,8 @@ pub struct TypeMap<'ll, 'tcx> { | |||
type_to_metadata: FxHashMap<Ty<'tcx>, &'ll DIType>, | |||
/// A map from types to `UniqueTypeId`. This is an N:1 mapping. | |||
type_to_unique_id: FxHashMap<Ty<'tcx>, UniqueTypeId>, | |||
/// A map from `UniqueTypeId` to it's type-name string. | |||
unique_id_to_type_name: FxHashMap<UniqueTypeId, 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.
A UniqueTypeId
already contains the string. A Symbol
is an interned 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.
So we can just check the type_to_unique_id
map instead right?
If there is a mapping, return the string by calling get_unique_type_id_as_string()
, otherwise create the mapping.
This would also mean that the Symbol
stored in UniqueTypeId
is the result of compute_debuginfo_type_name()
, but it isn't. the name is computed on this line in get_unique_type_id_of_type()
218 let key = self.unique_id_interner.intern(&unique_type_id)
My question is: if the resulting strings from the above line and compute_debuginfo_type_name()
are the same, isn't compute_debuginfo_type_name()
unnecessary in the first place?
Edit:
I am pretty sure that the string computed in compute_debuginfo_type_name()
and the Symbol
within a UniqueTypeId
are not the same.
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, seems like it is a hex encoded hash.
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 03361c46dd5c34a4b73ec159438486c64c15310d with merge db7e55346581a97b2acf2430c0b7b42c9da07e0b... |
☀️ Try build successful - checks-actions |
Queued db7e55346581a97b2acf2430c0b7b42c9da07e0b with parent b0ee495, future comparison URL. |
Finished benchmarking commit (db7e55346581a97b2acf2430c0b7b42c9da07e0b): comparison url. Summary: This benchmark run did not return any relevant changes. 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 |
Thanks for the PR, @Sl1mb0! I think for this to really make a performance difference the caching would have to be integrated into |
03361c4
to
69e911c
Compare
@michaelwoerister Do you have any suggestions on where caching should occur? |
The cache could live in the rust/compiler/rustc_codegen_llvm/src/debuginfo/mod.rs Lines 59 to 72 in e2750ba
You can try to add a |
☔ The latest upstream changes (presumably #88956) made this pull request unmergeable. Please resolve the merge conflicts. |
So I've changed a few things; but now the compiler is panicking due to a My guess is that it's because I am passing around a mutable reference to the cache, as opposed to passing around a The changes in these commits are:
|
I changed
|
Hm, that looks like a legitimate error: Meanwhile, if you clean up the merge conflicts we can run some performance tests via CI. |
a206b3a
to
cdd2ba2
Compare
This comment has been minimized.
This comment has been minimized.
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 left a few comments and might have found the reason for test failures. Give it a try :)
@@ -438,12 +438,11 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { | |||
substs: SubstsRef<'tcx>, | |||
name_to_append_suffix_to: &mut String, | |||
) -> &'ll DIArray { | |||
let type_name_cache = &mut *debug_context(cx).type_name_cache.borrow_mut(); |
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 holding the RefCell "lock" here for longer than just the type_names::push_generic_params()
call might have been the reason why you saw the BorrowMut panics because the type_metadata()
call farther below will also try to lock the cache.
7588659
to
fdd211a
Compare
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit fdd211a with merge 7cd33b678f6735d7b26fb78172256d815cb27b33... |
☀️ Try build successful - checks-actions |
Queued 7cd33b678f6735d7b26fb78172256d815cb27b33 with parent bf64232, future comparison URL. |
Finished benchmarking commit (7cd33b678f6735d7b26fb78172256d815cb27b33): comparison url. Summary: This benchmark run did not return any relevant changes. 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 |
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.
It looks like this doesn't improve performance much so far. We can try to improve things a little more by avoiding some string data allocations as described below. But I think that's as far as we can get as long as we don't find another way of dealing with recursive types.
@@ -62,6 +63,7 @@ pub struct CrateDebugContext<'a, 'tcx> { | |||
builder: &'a mut DIBuilder<'a>, | |||
created_files: RefCell<FxHashMap<(Option<String>, Option<String>), &'a DIFile>>, | |||
created_enum_disr_types: RefCell<FxHashMap<(DefId, Primitive), &'a DIType>>, | |||
type_name_cache: RefCell<FxHashMap<(Ty<'tcx>, bool), 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.
Replace String
with Rc<str>
so that we can cheaply copy strings. A String
can easily converted into an Rc<str>
as described here: https://doc.rust-lang.org/std/string/struct.String.html#impl-From%3CString%3E-3
This comment has been minimized.
This comment has been minimized.
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 353e42e with merge a35f2fa0b1709e3bffed26d72fff54832568660f... |
☀️ Try build successful - checks-actions |
Queued a35f2fa0b1709e3bffed26d72fff54832568660f with parent 175b8db, future comparison URL. |
Finished benchmarking commit (a35f2fa0b1709e3bffed26d72fff54832568660f): comparison url. Summary: This benchmark run did not return any relevant changes. 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 |
Well, it looks like there are no real performance improvements to be had here, unfortunately. Given that the changes add some complexity with no apparent gain, I'd opt for closing the PR (unless you have other ideas that we haven't explored yet). |
The only thing I can think of (without making a huge change) is that the mapping is too broad. The only field used from a If we get two different types, and they are each the same kind, we are computing that string for each type. I'll try it and if there's still no improvements I'll close the PR. |
Seems using a |
I hope you still had an interesting learning experience working on this, @Sl1mb0! |
This is a WIP addressing #86431. This PR aims to accomplish two things:
compute_debuginfo_type_name()
.compute_debuginfo_type_name()
and how many times we return a name for the cache. @rylev also suggested that determining how many individual memory allocations occur each time redundant work is performed, but I am unsure of how to go about this.