-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Restore HashMap performance by allowing some functions to be inlined #25070
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
Conversation
Since the hashmap and its hasher are implemented in different crates, we currently can't benefit from inlining, which means that especially for small, fixed size keys, there is a huge overhead in hash calculations, because the compiler can't apply optimizations that only apply for these keys. Fixes the brainfuck benchmark in rust-lang#24014.
(rust_highfive has picked a reviewer for you, use r? to override) |
@@ -120,6 +121,7 @@ impl SipHasher { | |||
self.ntail = 0; | |||
} | |||
|
|||
#[inline] | |||
fn write(&mut self, msg: &[u8]) { |
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.
Hm, it's unfortunate that this function is so large.
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.
Yeah, but that's also the most important function to have available for inlining, because most of it is thrown away when the compiler sees that, for example, it's only called with once with a single 8 byte slice. See my remark below about `#[inline(Maybe)].
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.
Very true.
For the record, I wonder whether we might want a |
#6616 is relevant. :) |
Since the hashmap and its hasher are implemented in different crates, we currently can't benefit from inlining, which means that especially for small, fixed size keys, there is a huge overhead in hash calculations, because the compiler can't apply optimizations that only apply for these keys. Fixes the brainfuck benchmark in #24014.
Since the hashmap and its hasher are implemented in different crates, we
currently can't benefit from inlining, which means that especially for
small, fixed size keys, there is a huge overhead in hash calculations,
because the compiler can't apply optimizations that only apply for these
keys.
Fixes the brainfuck benchmark in #24014.