Open
Description
Benchmark code:
package onepassword
import (
"context"
"testing"
)
const serviceAccountToken = "[secret]"
func BenchmarkNewClient(b *testing.B) {
// Warm up the WASM runtime.
_, err := NewClient(
context.Background(),
WithServiceAccountToken(serviceAccountToken),
WithIntegrationInfo(DefaultIntegrationName, DefaultIntegrationVersion),
)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := NewClient(
context.Background(),
WithServiceAccountToken(serviceAccountToken),
WithIntegrationInfo(DefaultIntegrationName, DefaultIntegrationVersion),
)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkResolveSecret(b *testing.B) {
const secretRef = "op://Test Vault/Example login/password"
// Warm up the WASM runtime.
client, err := NewClient(
context.Background(),
WithServiceAccountToken(serviceAccountToken),
WithIntegrationInfo(DefaultIntegrationName, DefaultIntegrationVersion),
)
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err = client.Secrets.Resolve(secretRef)
if err != nil {
b.Fatal(err)
}
}
}
Local results for 100x iterations:
1password-go-sdk ❯ go test . -benchtime 100x -bench "Benchmark.*" -cpuprofile cpu.out
goos: darwin
goarch: arm64
pkg: github.com/1password/onepassword-sdk-go
BenchmarkNewClient-10 100 1328848140 ns/op
BenchmarkResolveSecret-10 100 351173673 ns/op
PASS
ok github.com/1password/onepassword-sdk-go 175.427s
Local results for 1x iteration:
1password-go-sdk ❯ HTTPS_PROXY=http://localhost:8080 go test . -benchtime 1x -bench "Benchmark.*"
goos: darwin
goarch: arm64
pkg: github.com/1password/onepassword-sdk-go
BenchmarkNewClient-10 1 1329156334 ns/op
BenchmarkResolveSecret-10 1 403518250 ns/op
PASS
ok github.com/1password/onepassword-sdk-go 4.931s
Tracing the HTTP traffic for the last set of benchmark results shows the following calls on the NewClient
path:
13:44:31 HTTPS POST my.1password.com /api/v3/auth/start? 200 application/json 204b 111ms
13:44:32 HTTPS POST my.1password.com /api/v1/auth? 200 application/json 665b 92ms
13:44:32 HTTPS POST my.1password.com /api/v2/auth/verify? 200 application/json 899b 104ms
13:44:32 HTTPS GET my.1password.com /api/v2/account/keysets? 200 application/json 4.1k 89ms
It would be nice to have a way to cache the auth info if possible so that it can be shared between NewClient
invocations.
It's also a bit concerning that the HTTP traffic adds up to < 400ms while NewClient
takes 1.3s to execute. Unfortunately, the CPU profile is opaque due to the compiled WASM, so it is unclear what is happening during the other 900ms. Note that the benchmarks warm the WASM runtime by calling NewClient
once prior to the actual benchmark.
Metadata
Metadata
Assignees
Labels
No labels