Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merkle: optimize hashing by reusing sha256 in a pool
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 #43
- Loading branch information