You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let public_key = Secp256k1::verification_only().recover(&message,&signature)
This calls Secp256k1::verification_only() for each recover, creating a new context and recomputing all the lookup tables each time. This is documented in secp256k1:
[...] the library uses context objects that contain precomputation tables which are created on object construction. Since this is a slow operation (10+ milliseconds, vs ~50 microseconds for typical crypto operations, on a 2.70 Ghz i7-6820HQ) the tables are optional, giving a performance boost for users who only care about signing, only care about verification, or only care about parsing [...]
So we should statically allocate the context and initialize it once:
The
recover
function is unnecessarily slow. On my machine it takes about 7 ms instead of 60 μs.The cause is this line:
This calls
Secp256k1::verification_only()
for each recover, creating a new context and recomputing all the lookup tables each time. This is documented insecp256k1
:So we should statically allocate the context and initialize it once:
Benchmarking the above shows a 100x improvement:
The text was updated successfully, but these errors were encountered: