microsoft / go-crypto-openssl

Go crypto backend for Linux using OpenSSL
MIT License
61 stars 15 forks source link

Reduce SHA cgo calls #32

Closed qmuntal closed 2 years ago

qmuntal commented 2 years ago

We are using the *_ex variant of several OpenSSL functions which cause us more harm than good in terms of performance:

Taking into account that each cgo call overhead is ~80ns, getting rid of 3 cgo calls can make a difference when hashing small messages:

name          old time/op    new time/op    delta
Hash8Bytes-4    1.93µs ± 1%    1.23µs ± 3%  -36.46%  (p=0.000 n=9+10)

name          old speed      new speed      delta
Hash8Bytes-4  4.14MB/s ± 1%  6.51MB/s ± 3%  +57.38%  (p=0.000 n=9+10)

name          old memory/op   new memory/op   delta
Hash8Bytes-4     0.00B          0.00B          ~     (all equal)

name          old allocs/op  new allocs/op  delta
Hash8Bytes-4      0.00           0.00          ~     (all equal)