-
Notifications
You must be signed in to change notification settings - Fork 17
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
perf(merkle): optimize hashing by reusing sha256 in a pool #44
perf(merkle): optimize hashing by reusing sha256 in a pool #44
Conversation
1ccfc20
to
19dd495
Compare
This change optimizes SHA256 hashing for leafHash & innerHash by pooling and reusing hashes, which massively reduces on RAM consumption and even CPU time (benchmarking on my noisy machine is skewed but the results can be verified individually) producing the results below: ```shell $ benchstat before.txt after.txt name old time/op new time/op delta HashAlternatives/recursive-8 77.6µs ± 2% 77.0µs ± 2% ~ (p=0.165 n=10+10) HashAlternatives/iterative-8 76.3µs ± 1% 76.2µs ± 3% ~ (p=0.720 n=9+10) name old alloc/op new alloc/op delta HashAlternatives/recursive-8 25.4kB ± 0% 6.4kB ± 0% -74.94% (p=0.000 n=10+10) HashAlternatives/iterative-8 28.1kB ± 0% 9.1kB ± 0% -67.78% (p=0.000 n=10+10) name old allocs/op new allocs/op delta HashAlternatives/recursive-8 497 ± 0% 199 ± 0% -59.96% (p=0.000 n=10+10) HashAlternatives/iterative-8 498 ± 0% 200 ± 0% -59.84% (p=0.000 n=10+10) ``` Fixes celestiaorg#43
19dd495
to
af9405a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes seem fine to me but it's difficult to approve because the modified functions don't have unit tests. They should've had unit tests prior to this PR but I expect they don't because the merkle
package is copy + pasted from the CometBFT repo.
IMO we need to decide if it's okay for the merkle
package in this repo to diverge from the upstream CometBFT implementation. cc: @cmwaters
@rootulp how come the code was copied and pasted in here without the appropriate attributions/licenses or without just plain imports or submodules? |
I think this is relevant: Line 6 in 4e84d80
I suppose we could also copy + paste this license into that directory. |
Closing this because for now we've decided to keep the merkle library in our cometbft fork. Thanks for opening the PR in any case. Sorry that we didn't merge it. We may look to apply this to our cometbft fork in the future |
This change optimizes SHA256 hashing for leafHash & innerHash by pooling and reusing hashes, which massively reduces on RAM consumption and even CPU time (benchmarking on my noisy machine is skewed but the results can be verified individually) producing results below:
Fixes #43
Overview
Checklist