perf(state): eliminate speculative trie allocation storm via double-c…#2286
Open
shinobi133 wants to merge 4 commits into
Open
perf(state): eliminate speculative trie allocation storm via double-c…#2286shinobi133 wants to merge 4 commits into
shinobi133 wants to merge 4 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adjusts trieReader.subTrieConcurrent in core/state to avoid speculative per-address sub-trie allocations when many goroutines concurrently miss the subTries cache, aiming to reduce allocation/CPU spikes during parallel state reads.
Changes:
- Added a double-checked locking pattern around sub-trie creation to ensure only one goroutine creates and stores a missing sub-trie.
- Switched from
LoadOrStore“first-writer-wins” to explicit mutex-guardedStoreafter creation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+419
to
+421
| if v, ok := r.subTries.Load(addr); ok { | ||
| return v.(Trie), nil | ||
| } |
Comment on lines
+419
to
+441
| if v, ok := r.subTries.Load(addr); ok { | ||
| return v.(Trie), nil | ||
| } | ||
| // Optimize: Use r.lock to synchronize creation and prevent speculative allocation storms | ||
| r.lock.Lock() | ||
| if v, ok := r.subTries.Load(addr); ok { | ||
| r.lock.Unlock() | ||
| return v.(Trie), nil | ||
| } | ||
| root, err := r.resolveSubRoot(addr) | ||
| if err != nil { | ||
| r.lock.Unlock() | ||
| return nil, err | ||
| } | ||
| newTr, err := trie.NewStateTrie(trie.StorageTrieID(r.root, crypto.Keccak256Hash(addr.Bytes()), root), r.db) | ||
| if err != nil { | ||
| r.lock.Unlock() | ||
| return nil, err | ||
| } | ||
| newTr.EnableConcurrentReads() | ||
| r.subTries.Store(addr, newTr) | ||
| r.lock.Unlock() | ||
| return newTr, nil |
| if v, ok := r.subTries.Load(addr); ok { | ||
| return v.(Trie), nil | ||
| } | ||
| // Optimize: Use r.lock to synchronize creation and prevent speculative allocation storms |
Member
|
@shinobi133 - please fix the CI (lint) and address the comments |
|
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.



…hecked locking
Summary
<one paragraph: what changed and why. If the change has measurable impact, add a small table or numbers (e.g. perf delta on a kurtosis devnet, mutation kill rate). Link the JIRA / GH issue inline if there is one — not required.>
Executed tests
<what was actually run beyond CI's standard unit / integration / e2e gates: kurtosis scenarios, chaos runs, manual checks against Amoy / mainnet RPCs, devnet upgrades, etc. Include output or pointers to where the run lives.>
Rollout notes
<consensus-affecting? requires coordinated upgrade? backwards-compatible? operator-facing change?>