penumbra-zone / poseidon377

An instantiation of the Poseidon hash for use with decaf377
https://protocol.penumbra.zone/main/crypto/poseidon.html
Other
28 stars 10 forks source link

perf: don't use const with once_cell #23

Closed redshiftzero closed 2 years ago

redshiftzero commented 2 years ago

I profiled the hash_4 function in poseidon377 -- previously (in #21) I had focused on profiling the permute method where I had assumed 99% of the computation would be happening -- and it appears we've been using once_cell wrong in this repo. The docs state that using const for the Lazy variable will compile however it "works wrong" - instead static must be used. In our case this meant that every time we accessed the parameters struct, we were actually creating it all over again, resulting in a ton of wasted computation.

tl;dr This means I think that the speedup should not be not 30% as reported in #21 but closer to 30X - from testing on my M1 it's about 615us before vs 22us after (per hash)