Skip to content
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

Move hashn() calculations inline to callers #6

Closed
dgryski opened this issue Apr 13, 2014 · 2 comments
Closed

Move hashn() calculations inline to callers #6

dgryski opened this issue Apr 13, 2014 · 2 comments

Comments

@dgryski
Copy link
Collaborator

dgryski commented Apr 13, 2014

Currently, hashn() allocates a new slice of the hash values and returns it. This causes an allocation that we could get rid of if we instead chose to return h1 and h2 and let the caller compute the different hash values.

This changes the callers from

for i, pos := range hashn(h, d, w) {

to

h1, h2 := hashn(h)
for i := 0; i < d; i++ {
    pos := (h1 + uint32(i)*h2) % uint32(w)

Removing these allocations In my tests this speeds up the hashing code by a factor of 2 (~1500ns/op to ~750ns/op).

I have a patch that does this, but it touches a bunch of code so I thought I'd clear this with you before pushing.

@dustin
Copy link
Owner

dustin commented Apr 14, 2014

Sure, speeding stuff up sounds like a great idea. :)

dgryski added a commit that referenced this issue Apr 17, 2014
The previous implementation of hashn() return a slice of ints, requiring
an allocation.  This made sense when the hashing algorithms were more
complex, but since they're just linear combinations, we can do that in
the caller instead.  This removes an allocation which ends up doubling
the speed of the hash function: from ~1500ns/op to ~750ns/op.

Fixes issue #6.
@dgryski
Copy link
Collaborator Author

dgryski commented Apr 17, 2014

Looks like I didn't get the magic words right in the commit message to auto-close this.

@dgryski dgryski closed this as completed Apr 17, 2014
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

No branches or pull requests

2 participants