Skip to content

Conversation

orlp
Copy link
Owner

@orlp orlp commented Aug 6, 2025

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 the write 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).

@orlp orlp force-pushed the better-str-inline branch from ba8c34c to f7a0f48 Compare August 6, 2025 00:25
@orlp orlp force-pushed the better-str-inline branch from f7a0f48 to c0a7087 Compare August 6, 2025 00:26
}

impl FoldHasher {
impl<'a> FoldHasher<'a> {
Copy link
Contributor

@hoxxep hoxxep Aug 6, 2025

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!

@hoxxep
Copy link
Contributor

hoxxep commented Aug 6, 2025

StrUuid/hashonly-struuid-foldhash-fast                                                                             
                        time:   [3.9845 ns 3.9967 ns 4.0155 ns]
                        change: [-28.221% -27.992% -27.688%] (p = 0.00 < 0.05)
                        Performance has improved.

StrDate/hashonly-strdate-foldhash-fast                                                                             
                        time:   [1.3822 ns 1.3871 ns 1.3940 ns]
                        change: [-74.410% -74.321% -74.187%] (p = 0.00 < 0.05)
                        Performance has improved.

StrEnglishWord/hashonly-strenglishword-foldhash-fast                                                                             
                        time:   [1.4817 ns 1.4838 ns 1.4862 ns]
                        change: [-73.297% -73.247% -73.193%] (p = 0.00 < 0.05)
                        Performance has improved.

StrUrl/hashonly-strurl-foldhash-fast                                                                             
                        time:   [6.4448 ns 6.4922 ns 6.5401 ns]
                        change: [-12.745% -12.003% -11.230%] (p = 0.00 < 0.05)
                        Performance has improved.

LGTM!

@orlp orlp merged commit 12bbffe into master Aug 6, 2025
@@ -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.
Copy link

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.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be, yes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants