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

Add noescape and nocallback directive to EVP_PKEY_derive #113

Merged
merged 1 commit into from
Aug 31, 2023
Merged

Conversation

qmuntal
Copy link
Collaborator

@qmuntal qmuntal commented Aug 30, 2023

noescape and nocallback are new go1.22 cgo directives that helps the Go compiler take better decisions. See golang/go#56378 for more context.

In this PR I've tagged EVP_PKEY_derive with both directives, which allows the keylen parameter to stay on the stack. EVP_PKEY_derive is currently used in ECDH, HKDF and TLS1PRF, so they will all automatically benefit from this optimization.

Benchmark prove for ECDH:

goos: windows
goarch: amd64
pkg: github.com/golang-fips/openssl/v2
cpu: Intel(R) Core(TM) i7-10850H CPU @ 2.70GHz
        │   old.txt    │            new.txt             │
        │    sec/op    │    sec/op     vs base          │
ECDH-12   53.01µ ± 12%   53.24µ ± 11%  ~ (p=0.853 n=10)

        │  old.txt   │              new.txt               │
        │    B/op    │    B/op     vs base                │
ECDH-12   40.00 ± 0%   32.00 ± 0%  -20.00% (p=0.000 n=10)

        │  old.txt   │              new.txt               │
        │ allocs/op  │ allocs/op   vs base                │
ECDH-12   2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)

Copy link
Collaborator

@dagood dagood left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Unsurprisingly the same result on linux_amd64:

goos: linux
goarch: amd64
pkg: github.com/golang-fips/openssl/v2
cpu: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
       │ before.txt  │           after.txt           │
       │   sec/op    │   sec/op     vs base          │
ECDH-8   103.2µ ± 4%   101.3µ ± 1%  ~ (p=0.218 n=10)

       │ before.txt │             after.txt              │
       │    B/op    │    B/op     vs base                │
ECDH-8   40.00 ± 0%   32.00 ± 0%  -20.00% (p=0.000 n=10)

       │ before.txt │             after.txt              │
       │ allocs/op  │ allocs/op   vs base                │
ECDH-8   2.000 ± 0%   1.000 ± 0%  -50.00% (p=0.000 n=10)

@qmuntal qmuntal merged commit c96fdff into v2 Aug 31, 2023
16 checks passed
@qmuntal qmuntal deleted the derivopt branch August 31, 2023 10:00
@doujiang24
Copy link

https://go-review.googlesource.com/c/go/+/539235
fyi: it's disabled in go 1.22, will enable in go 1.23.

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.

None yet

4 participants