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

issue 158: Add SmallState #226

Merged
merged 4 commits into from Mar 26, 2024
Merged

issue 158: Add SmallState #226

merged 4 commits into from Mar 26, 2024

Conversation

tkaitchuck
Copy link
Owner

Is an optional reduced size state.
Fixes #158

Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
@tkaitchuck tkaitchuck marked this pull request as ready for review March 21, 2024 05:47
@arthurprs
Copy link

I performed a quick benchmark with runtime-rng enabled (the most common feature I suppose) and the time to hash a 10 byte string goes from 2.5ns to 12.3ns, which puts it in siphash territory.

Do you think we could take some liberties with the creation of RandomState from SmallState, like

        let [a, _] = get_fixed_seeds();
        AHasher::from_random_state(&RandomState {
            k0: self.key as u64 ^ a[0],
            k1: self.key as u64 ^ a[1],
            k2: self.key as u64 ^ a[2],
            k3: self.key as u64 ^ a[3],
            _h: PhantomData::<T>,
        })

This brings it down from 12ns to 4ns

Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
@tkaitchuck
Copy link
Owner Author

tkaitchuck commented Mar 25, 2024

@arthurprs The code you have there won't be sufficiently strong. But I have tried to speed it up. Give it another try.

Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
@arthurprs
Copy link

I got 7ns for 3e14ceb and 6.3ns for 1e94eac.
For context, it's 2.5ns for the regular ahash and 10.3ns for sip13.

I think it's good now, unless you can squeeze more out of it 🚀

@tkaitchuck
Copy link
Owner Author

I think I should be able to lower the added overhead by another 20%.

Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
@tkaitchuck
Copy link
Owner Author

tkaitchuck commented Mar 26, 2024

@arthurprs Is e2ae7b7 any faster on your system? It should be, but it my tests it appears to be, but only by about the same margin as random variation, so I am not sure if it is significant.

@arthurprs
Copy link

arthurprs commented Mar 26, 2024

I can confirm the latest commit (~5ns) is 12% faster than the previous.

@tkaitchuck tkaitchuck merged commit 0a0e493 into 0.9-prerelease Mar 26, 2024
18 checks passed
@tkaitchuck tkaitchuck deleted the length_specialization branch March 26, 2024 15:13
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.

None yet

2 participants