Skip to content

ristretto/z: use hash/memhash for hashing #160

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

Closed
wants to merge 1 commit into from

Conversation

rogpeppe
Copy link

@rogpeppe rogpeppe commented Jun 5, 2020

This is cleaner, but unfortunately slower.

Reusing the Hash value in KeyToHash may help there,
but wouldn't get back to the original speed, so maybe
this isn't a reasonable change.

name             old time/op    new time/op    delta
MemHash-4          12.4ns ± 7%    43.1ns ± 1%  +248.30%  (p=0.008 n=5+5)
MemHashString-4    19.6ns ± 7%    70.9ns ±20%  +262.00%  (p=0.008 n=5+5)

name             old speed      new speed      delta
MemHash-4        5.17GB/s ± 7%  1.48GB/s ± 0%   -71.31%  (p=0.008 n=5+5)
MemHashString-4  6.29GB/s ± 6%  1.75GB/s ±18%   -72.12%  (p=0.008 n=5+5)

name             old alloc/op   new alloc/op   delta
MemHash-4           0.00B          0.00B           ~     (all equal)
MemHashString-4     0.00B          0.00B           ~     (all equal)

name             old allocs/op  new allocs/op  delta
MemHash-4            0.00           0.00           ~     (all equal)
MemHashString-4      0.00           0.00           ~     (all equal)

This change is Reviewable

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

This is cleaner, but unfortunately slower.

Reusing the Hash value in KeyToHash may help there,
but wouldn't get back to the original speed, so maybe
this isn't a reasonable change.

```
name             old time/op    new time/op    delta
MemHash-4          12.4ns ± 7%    43.1ns ± 1%  +248.30%  (p=0.008 n=5+5)
MemHashString-4    19.6ns ± 7%    70.9ns ±20%  +262.00%  (p=0.008 n=5+5)

name             old speed      new speed      delta
MemHash-4        5.17GB/s ± 7%  1.48GB/s ± 0%   -71.31%  (p=0.008 n=5+5)
MemHashString-4  6.29GB/s ± 6%  1.75GB/s ±18%   -72.12%  (p=0.008 n=5+5)

name             old alloc/op   new alloc/op   delta
MemHash-4           0.00B          0.00B           ~     (all equal)
MemHashString-4     0.00B          0.00B           ~     (all equal)

name             old allocs/op  new allocs/op  delta
MemHash-4            0.00           0.00           ~     (all equal)
MemHashString-4      0.00           0.00           ~     (all equal)
```
@manishrjain
Copy link
Contributor

Thanks for the PR, @rogpeppe . Yeah, the speeds don't look encouraging, though I'm wondering why that's the case. My understanding was that Go 1.14 exposed the same functions.

@rogpeppe
Copy link
Author

rogpeppe commented Jun 6, 2020

Yeah, me too. I did it in a rush over about 20 minutes before bed last night so didn't have time to investigate more. I'm interested why it's so much slower - I might take another look today.

@nes1983
Copy link

nes1983 commented Jun 10, 2020

Just peeking at your code, I don't think you're using maphash the way it's meant to be used. You're supposed to use one maphash struct per goroutine, you're not supposed to create a fresh struct for each hash call. But that's what the code does. This leads to a ton of unneeded allocation. So I'm not surprised this winds up being slower than the original.

Copy link

This PR has been stale for 60 days and will be closed automatically in 7 days. Comment to keep it open.

@github-actions github-actions bot added the Stale label Jul 19, 2024
@github-actions github-actions bot closed this Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

4 participants