Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RSA/ECDSA performance #13

Merged
merged 1 commit into from
Feb 24, 2022
Merged

Improve RSA/ECDSA performance #13

merged 1 commit into from
Feb 24, 2022

Conversation

qmuntal
Copy link
Member

@qmuntal qmuntal commented Feb 22, 2022

RSA/ECDSA throughput can't be significantly improved because the bottleneck is in the OpenSSL cgo call that performs the crypto heavy lifting, namely EVP_PKEY_encrypt, EVP_PKEY_decrypt, EVP_PKEY_sign, or EVP_PKEY_verify. These accounts for ~93% of the processing time.

Batching cgo calls nor reducing GC pressure help increase the throughput because we are at the order of 10.000 ns/op, much higher than the ~60ns cgo overhead and whatever the GC latency has.

On the other hand, we can reduce the allocations by defining EVP_PKEY and EVP_PKEY_CTX pointer types in C instead of Go. This trick avoids filling Go heap with unnecessary pointers unless strictly necessary.

This PR only adds a benchmark for EncryptRSAPKCS1. All rsa/ecdsa functions are implemented reusing almost the same code so benchmarking one is representative enough.

The result is that we have not improved throughput, but we have reduced allocated memory and objects.

name               old time/op    new time/op    delta
EncryptRSAPKCS1-4    13.2µs ± 3%    13.2µs ± 5%     ~     (p=1.000 n=10+10)

name               old B/op   new B/op   delta
EncryptRSAPKCS1-4      352B ± 0%      296B ± 0%  -15.91%  (p=0.000 n=10+10)

name               old allocs/op  new allocs/op  delta
EncryptRSAPKCS1-4      11.0 ± 0%       5.0 ± 0%  -54.55%  (p=0.000 n=10+10)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants