perf: prepare Ed25519 verifying keys at import time - #139
Conversation
e98f861 to
c82991f
Compare
|
Thank you for this contribution, it's useful! Two questions:
I'm mostly just trying to figure out whether an external dependency is really needed and, if so, how it should be packaged so that we can run this bench automatically. |
I really like to use hyperfine. Let me rerun it in cargo bench to check if we are seeing the same results. If so, let me remove the comment. You are right that this should not be a new mandatory test dependency |
VerifyingKey::try_from was executed on every verification. Keys are now prepared once when a keyring entry is created and borrowed during verification. Invalid raw key material keeps the deferred InvalidKeyLength behavior; public APIs are unchanged. Adds a deterministic harness=false benchmark (keyring_verify) with verify-only and end-to-end modes. Assisted-By: devx/bcb08cbe-f194-4c2c-a5a0-0c3b36297da9
c82991f to
ea6b807
Compare
removed hyperfine and used cargo bench exclusively. |
Summary
MessageVerifier::verifyranVerifyingKey::try_fromon every Ed25519 request, repeating point decompression for keys that never change. Keys are now prepared once when a keyring entry is created (import_raw,FromIterator, JWK import, rename all covered) and borrowed during verification.Internally the ring stores
{ raw, prepared }entries;rawkeeps the publicgetAPI unchanged.preparedisOption<VerifyingKey>:Nonepreserves the existing deferredInvalidKeyLengthresult for raw bytes that cannot form a valid key. No public API or error-behavior changes. We run this verifier in a high-throughput edge component, where the per-request savings accumulate.Testing
cargo +stable test --workspace --all-features --all-targets: 38 pass, incl. new tests for invalid key material, invalid signature, unsupported algorithm, duplicate import, renamed key.cargo +stable clippy --workspace --all-features --all-targets -- -D warnings: clean.cargo fmt --check: clean.cargo +stable bench -p web-bot-auth --bench keyring_verify: runs bothverify-onlyandend-to-endwith 30,000 iterations and prints nanoseconds per iteration. No additional benchmark dependency is required.A three-run local A/B using the committed
cargo benchtarget produced these median results:As an additional manual cross-check, I ran a locally installed Hyperfine binary against baseline and optimized executables built with identical flags (
-C llvm-args=-align-all-functions=6). Hyperfine is not a project dependency and is not required to run the committed benchmark. Twenty runs in both command orderings produced:Approximately 2.1 microseconds saved per verification; no end-to-end regression.