-
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
[Incremental] Cache hashes for AdDef and ty::Slice<T> #47373
Conversation
src/librustc/ich/impls_ty.rs
Outdated
} | ||
|
||
let hash = CACHE.with(|cache| { | ||
let addr = &**self as *const ty::Slice<T> as *const usize as usize; |
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 you check this? I tried self as *const ty::Slice<T> as usize
but got a casting error. The suggested fix in #41300 resolved the error but I'm not really sure why it works.
src/librustc/ty/mod.rs
Outdated
|
||
let hash = CACHE.with(|cache| { | ||
let addr = self as *const AdtDef as usize; | ||
if let Some(&hash) = cache.borrow().get(&addr) { |
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.
Since AdtDef
s are not recursive, you should be able to slightly optimize this by using HashMap::entry()
. That avoids having to look up the key twice in the "cache miss" case.
You cannot do the same for ty::Slice
because while hashing one slice, you might encounter a nested one somewhere down the line and consequently run into a RefCell
double-borrow panic.
src/librustc/ty/mod.rs
Outdated
@@ -1483,10 +1485,29 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for AdtDef { | |||
ref repr, | |||
} = *self; |
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 would move this whole block into the closure, after the "cache hit" case.
Right, a What you did should be correct but is a bit roundabout. First you are converting I would suggest that you do the same thing as the Line 571 in 73ac5d6
This makes use of the Since the So I would make the cache key |
|
c8adecd
to
eab3bfc
Compare
Thanks @michaelwoerister! I think I've addressed all of your concerns in the latest revisions. |
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.
Looks good! If you remove that redundant line I commented on below, this should be ready for a performance test.
src/librustc/ty/mod.rs
Outdated
repr.hash_stable(hcx, &mut hasher); | ||
|
||
let hash: Fingerprint = hasher.finish(); | ||
(addr, hash); |
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.
This line seems to be a leftover from something.
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.
Oops, I'm not even sure where that came from lol
eab3bfc
to
45bd091
Compare
Fixed |
Excellent. I'll start a try-build so we can measure the performance impact. @bors try |
[Incremental] Cache hashes for AdDef and ty::Slice<T> r? @michaelwoerister
☀️ Test successful - status-travis |
Perf queued. |
perf.rlo link ( |
Nice! These are some pretty good performance improvements. If it doesn't cause any trouble with further testing, we might even want to backport it to the current beta, given how small the change set is. Thank you, @wesleywiser! @bors r+ |
📌 Commit 45bd091 has been approved by |
Thanks @michaelwoerister! |
…ster [Incremental] Cache hashes for AdDef and ty::Slice<T> r? @michaelwoerister
☀️ Test successful - status-appveyor, status-travis |
Very good numbers for a single optimization |
r? @michaelwoerister