-
Notifications
You must be signed in to change notification settings - Fork 42
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
Support hashtree
crate with feature, add Criterion benchmarks
#161
base: main
Are you sure you want to change the base?
Conversation
With the latest commit getting rid of heap allocation for chunks and replacing it with an array, benchmarks were even better for
|
hashtree
crate with featurehashtree
crate with feature, add Criterion benchmarks
I think this shouldn't close #156 this PR creates a wrapper that hashes two chunks, not necessarily contiguous with hashtree. As such it only benefits from the padding block prescheduling of hashtree but none of the vectorized/parallel pipelining. This is why you are getting only 16%--20% benefits from it. When hashing two chunks at the time you also incur on copies and allocations for every chunk you hash, something that is utterly unnecessary in most situations. The approach to actually gain from this library is to hash one entire layer at the time, by passing all the layer, contiguously allocated, to the You can hash a Merkle tree of base 2^{N+1} by allocating only 2^N for the first layer, and then rewriting that allocated layer on successive runs, by passing the same slice as |
@potuz agreed this doesn't resolve the whole issue. I will follow this up with another PR for the other performance improvements you mentioned. |
Implements a new
hash_chunks
method that is used everywhere and will vary on implementation based on the features enabled.Related to #156 but further optimizations are possible.
Notes
hash_chunks
function, whose implementation differs based on the enabled features. I've tried adding a generic hasher trait and using dynamic dispatch, but this became pretty messy. I think this is cleaner.Benchmarks
sha2 (default)
sha2-asm
hashtree
In these benchmarks,
hashtree
is ~16% faster at generating proofs and ~20% faster at calculating hash tree roots compared tosha2-asm
.