-
Notifications
You must be signed in to change notification settings - Fork 969
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
Add non-serializing XDR hashers for SHA256 and ShortHash. #2093
Conversation
Cool. A few ideas/comments:
|
Ok.
Don't merge this until our sodium repo has absorbed the sodium change in some form. I don't think I agree that stopping short of hashing the full input is wise; there's no generic way of knowing which bytes in the input are likely stable vs. likely to change between different keys, and guessing wrong means only hashing the stable keys and then the hashtable degrades to linear search (everything hashes to the same bucket). I also think the cost of byteswapping integer fields is negligible relative to the other costs of hashing here, and keeping it in place makes the code easy to test by comparison to serialization; removing it seems to me not worth it. Perf measurements follow:
|
We'll revive this for 12.1.0 |
94851b7
to
47cb92a
Compare
Ok, it looks like libsodium is declining to take the patch, so that puts us back to the first approach: integrate a small incremental-able 3rd-party implementation of siphash ourselves. Updated and rebased patch to do that. |
47cb92a
to
9c1c9f0
Compare
Finally pushed variant that combines small-buffer use as in the libsodium attempt with the 3rd party incremental version of siphash: both are required to beat (performance-wise) the serialize-to-a-buffer-then-hash approach, and even then we only beat by a small margin. I still think this is probably worth doing at least because it gets another heavy user of the allocator out of the picture, which makes profiling allocations easier / less noisy, and means we're less performance-coupled to allocator speed. But it's not a slam dunk, if you don't like the look of this patch we can close it out.
|
r+ 9c1c9f0 |
Add non-serializing XDR hashers for SHA256 and ShortHash. Reviewed-by: MonsieurNicolas
Description
This adds a new implementation of SipHash (borrowed from the internet -- it's quite a standard function and there are zillions of implementations) that operates in incremental mode, allowing us to stream data through it rather than only hashing ByteSlices.
Additionally, it adds an XDR archiver class that streams the bytes of an XDR object's serial representation through such a SipHasher, without allocating/serializing/freeing a byte buffer.
This should let us replace many of the cases we're using allocation-hungry hash functions in hashtables keyed by XDR values. Saw another of these in @jonjove's recent PR, figured I'd fix the problem at the source!
Checklist
clang-format
v5.0.0 (viamake format
or the Visual Studio extension)