Repository navigation
Shard verifySig cache to reduce mutex contention. - #5286
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces lock contention in the global Ed25519 signature-verification result cache by sharding it into multiple independently-locked caches, improving throughput when signature verification occurs concurrently across threads. It also removes the protocol-gated switch to Rust ed25519-dalek verification and uses the Rust verifier unconditionally.
Changes:
- Replace the single global
RandomEvictionCache+ mutex with 16 sharded caches (one mutex per shard). - Switch cache lookups from
exists()/get()tomaybeGet()to avoid a double hash-table lookup on hits. - Remove the protocol-version-triggered
enableRustDalekVerify()mechanism and always verify via the Rust dalek bridge.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/ApplicationImpl.cpp | Removes protocol-version-based enablement of Rust dalek verification during startup. |
| src/ledger/LedgerManagerImpl.cpp | Removes protocol-version-based enablement of Rust dalek verification when setting LCL. |
| src/herder/Upgrades.cpp | Removes Rust dalek enablement at the protocol version upgrade boundary. |
| src/crypto/test/CryptoTests.cpp | Removes explicit test-time enabling of Rust dalek verification. |
| src/crypto/SecretKey.h | Removes the enableRustDalekVerify() declaration and related comments. |
| src/crypto/SecretKey.cpp | Implements sharded verifySig cache, atomic hit/miss counters, and unconditional Rust dalek verification. |
|
A few nits. One performance observation though. While this is an improvement, we still have a blocking dependency when we hash anything due to It doesn't seem like we actually need this mutex either. It's just to protect our initial hash seed, which we just set once on startup. We do modify the seed in test contexts, but is there any reason we can't just move the mutex behind BUILD_TESTS? |
ShortHash locking has been removed a while ago, this branch is just very old. So it shouldn't be an issue anymore. FWIW I've also prototyped the lock-free version of cache, but it's sketchy and doesn't seem worth it based on benchmarks. Also, there was yet another global mutex, which was easily replaceable with atomics. |
Replace the single signature cache global mutex + RandomEvictionCache with 64 sharded caches (each with its own mutex) so concurrent signature verification threads no longer block on a shared lock. In addition, replace another global mutex for metrics with atomic counters. Also use the single-lookup maybeGet() in place of the exists()/get() double-lookup and use Rust verification unconditionally.

Description
Replace the single global mutex + RandomEvictionCache with 16 sharded caches (each with its own mutex) so concurrent signature verification threads no longer block on a shared lock.
Also use the single-lookup maybeGet() in place of the exists()/get() double-lookup and use Rust verification unconditionally (an overdue cleanup).
Checklist
clang-formatv8.0.0 (viamake formator the Visual Studio extension)