Repository navigation
arbos/storage: shard the keccak cache to remove a global mutex - #4767
Closed
paranoiacblack wants to merge 5 commits into
Closed
paranoiacblack wants to merge 5 commits into
paranoiacblack wants to merge 5 commits into
Conversation
geth's lru.Cache guards one BasicLRU with a single sync.Mutex, and Get takes it in write mode because a lookup reorders recency. Storage.mapAddress consults that cache once per storage slot, and every eth_call opens ArbOS state before executing an opcode, so the cache serialises RPC and block execution process-wide. Spread it over independently locked shards, selected by maphash of the key. Keys are a shared subspace prefix followed by a slot, so slicing a prefix would put a subspace on one shard; hashing avoids that. storageKeyCacheSize becomes the per-shard capacity, so the cache now holds 64x as many entries (~6.5MB). That also addresses the "Hash cache full, we didn't expect that" warning, which fires on nodes serving real eth_call load.
eljobe
reviewed
Oct 16, 2026
eljobe
left a comment
Member
There was a problem hiding this comment.
You also need to add a changelog entry.
Co-authored-by: Pepper Lebeck-Jobe <eljobe@gmail.com>
Co-authored-by: Pepper Lebeck-Jobe <eljobe@gmail.com>
Co-authored-by: Pepper Lebeck-Jobe <eljobe@gmail.com>
The suggested TestShardedHashCacheSpreadsKeys body calls maphash.String directly, which needs hash/maphash in the imports. Applying the suggestion on its own left the package not compiling. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Author
Done, PTAL. |
Member
|
Thanks, @paranoiacblack. Your diagnosis and profile were spot on and led directly to our fix. We're closing this in favor of a different approach. The "Hash cache full" warning was a bug: ticket IDs and per-transaction slots were going into a cache meant only for keys fixed by code. Once those keys are kept out, the cache stays at about 50 entries and can be read with no lock. On 14 cores, opening ArbOS state drops from 24.7µs to 2.0µs. It will ship in an upcoming release. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Storage.cachedKeccakuseslru.NewCache[string, []byte], which guards oneBasicLRUwith a singlesync.Mutex.Gettakes it in write mode because a lookup reorders recency, so it is not a read-mostly lock.Storage.mapAddressconsults that cache once per storage slot, and everyeth_callopens ArbOS state before executing an opcode:Block insertion opens ArbOS state through the same path, so RPC and block execution contend on one lock.
We hit this on a self-hosted archive node (v3.12.1, 64 vCPU) under eth_call load. Goroutine profile at the time:
rpc.(*handler).close->WaitGroup.Waitlru.(*Cache).Get->Mutex.LockapplyMessageWithEVM(actually executing)The node held ~10% CPU with disk idle while block execution went from 3.4ms to 1,744ms p50 and it fell behind the chain. Adding cores did not help, which is what a single mutex looks like.
Change
Shard the cache across independently locked
lru.Cacheinstances, selected bymaphashof the key. Keys are a shared subspace prefix followed by a slot, so slicing a prefix would land a whole subspace on one shard; hashing avoids that.storageKeyCacheSizebecomes the per-shard capacity. With 64 shards the cache holds 65,536 entries rather than 1,024, roughly 6.5MB. That is deliberate: the existing"Hash cache full, we didn't expect that"warning fires on nodes serving real eth_call traffic. If you would rather hold total capacity constant, setstorageKeyCacheSizeto 16 and only the contention fix remains.Benchmark
BenchmarkHashCacheGetParallel, 16-core arm64,-benchtime=3s.shards=1is current behaviour.Today's cache gets slower as goroutines are added (22.7 -> 140.2 ns). Sharded, it stays roughly flat. 3.6x at 16 goroutines, and the gap widens with core count.
Testing
go testpasses for the new file: round-trip, power-of-two shard rounding, and key spread across shards.I could not run the full
arbos/storagesuite locally because the package needs generatedsolgenbindings and I do not have the Solidity toolchain set up. The new code depends only oncommon/lru,hash/maphashandmath/bits, andcachedKeccakis unchanged sinceGet/Addkeep their signatures. Worth a CI run before trusting it.Happy to adjust shard count, capacity, or split the capacity change into its own PR.