-
Notifications
You must be signed in to change notification settings - Fork 19
Improve short-string performance by helping inlining #35
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
} | ||
|
||
impl FoldHasher { | ||
impl<'a> FoldHasher<'a> { |
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 quite like how adding the lifetime parameter turned out, I expected it to be more of a pain in various ways. Slightly regret not taking this option in rapidhash now!
LGTM! |
@@ -220,8 +220,64 @@ const fn rotate_right(x: u64, r: u32) -> u64 { | |||
} | |||
} | |||
|
|||
/// Hashes strings >= 16 bytes, has unspecified behavior when bytes.len() < 16. | |||
fn hash_bytes_medium(bytes: &[u8], mut s0: u64, mut s1: u64, fold_seed: u64) -> u64 { | |||
/// Hashes strings <= 16 bytes, has unspecified behavior when bytes.len() < 16. |
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.
Shouldn't the comment be:
Hashes strings <= 16 bytes, has unspecified behavior when bytes.len() > 16.
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 should be, yes.
Credit to @hoxxep for identifying and bringing my attention to this issue. The body of
Hasher::write
was too large which could (depending on linker /codegen-units
) prevent proper inlining of the sponge construction. By passing the seeds by reference and not inlining the longer string path thewrite
body is now sufficiently small to consistently inline. All-in-all on my machine this resulted in a 4x improvement for short strings. This is an improvement over the original benchmarks (which had since benchmarking regressed).