ferranbt / fastssz

Fast Ethereum2.0 SSZ encoder/decoder
MIT License
73 stars 44 forks source link

Increase performance of repeat proving. #168

Closed mcdee closed 1 month ago

mcdee commented 1 month ago

Repeatedly running Prove() against the same node can take a long time, as hashes are unconditionally recomputed. This simple change checks for the presence of a value in an intermediate node before rehashing.

Performance difference as follows:

goos: linux
goarch: amd64
pkg: github.com/ferranbt/fastssz
cpu: 12th Gen Intel(R) Core(TM) i7-1265U
         │    before.txt    │              after.txt               │
         │      sec/op      │    sec/op     vs base                │
Prove-12   247529.077µ ± 5%   4.283µ ± 34%  -100.00% (p=0.002 n=6)

This also returns the value being proved even if it is an intermediate node.

Test for repeated proving and a benchmark for repeated proving included.