execution/cache: track GenericCache entry count in an atomic, not freelru's all-shard Len - #23521
Closed
AskAlexSharov wants to merge 1 commit into
Closed
execution/cache: track GenericCache entry count in an atomic, not freelru's all-shard Len#23521AskAlexSharov wants to merge 1 commit into
AskAlexSharov wants to merge 1 commit into
Conversation
…elru's all-shard Len Every insert into a cache below its growth ceiling ran the grow check through freelru's ShardedLRU.Len, which RLocks all shards in turn (up to GOMAXPROCS*16). That serialised writers on shards they never touch, and ShardedLRU.Get takes the shard's write lock, so readers convoyed behind it too. Pair each generation of the LRU with an atomic entry count maintained by the insert path and the OnEvict callback, and read that instead. BenchmarkGenericCacheParallelPutGrow, M4 Max, -cpu 10: 466.3n -> 163.7n (-64.9%, p=0.002 n=6). The gap widens with core count. Claude-Session: https://claude.ai/code/session_01WFkAYPPhqPe1NXg41Nph78
Collaborator
Author
|
Superseded by #23522 — same commit, branch renamed to |
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.
Every insert into a
GenericCachebelow its growth ceiling ran the grow check throughfreelru.ShardedLRU.Len, which RLocks every shard in turn (up toGOMAXPROCS*16). That serialised writers on shards they never touch — and sinceShardedLRU.Gettakes the shard's write lock, readers convoyed behind it too.Fix: pair each generation of the LRU with an atomic entry count, maintained by the insert path (+1) and the existing
OnEvictcallback (-1), and read that on the hot path.Len(), theModeNoOpadmission check andmaybeGrow's re-check all use it.BenchmarkGenericCacheParallelPutGrow(added), M4 Max,-cpu 10:The gap widens with core count — the laptop only has 256 shards.
Two tests pin the new invariant (counter == the LRU's real length) across insert / update / delete / lazy stale drop / capacity eviction / grow /
Clear, sequentially and under concurrency. Both were verified to fail against a mutated counter.No TDD cycle: this is a performance refactor with no intended behaviour change; the existing suite is the safety net.
Follow-up, not in this PR:
growLRU.Add(grow_lru.go, used byCodeCache) has the same per-addLen().https://claude.ai/code/session_01WFkAYPPhqPe1NXg41Nph78