Periodically evict finalized states in checkpoint states cache#16458
Merged
Periodically evict finalized states in checkpoint states cache#16458
Conversation
44c05d5 to
86e0c43
Compare
86e0c43 to
16123a5
Compare
16123a5 to
2a4cb08
Compare
2a4cb08 to
23c20d1
Compare
potuz
reviewed
Mar 5, 2026
beacon-chain/blockchain/service.go
Outdated
| go s.runLateBlockTasks() | ||
| } | ||
|
|
||
| // spawnCheckpointStateCacheEvictionRoutine runs a background goroutine that |
Contributor
There was a problem hiding this comment.
Why do you need this extra routine? you're in the blockchain package, just hook it onto executePostFinalizationTasks or similar.
potuz
requested changes
Mar 5, 2026
potuz
approved these changes
Mar 5, 2026
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.
What type of PR is this?
Bug fix
What does this PR do? Why is it needed?
This PR evicts finalized states in checkpoint states cache.
States are efficiently stored in caches, especially thanks to multi value slices. If 1 state takes 300 MB and 2 states that are really similar are stored in a cache, then these 2 states could only need let's say 310MB of cache memory (instead of 300 MB x 2 = 600 MB).
Before the commit creating the memory issue, new states were regularly stored in the
CheckpointStateCache. This cache has 10 slots.After this cache is full, oldest values (not quite exactly because it's a LRU cache) are pruned.
After the commit creating the memory issue, new states are quite rarely inserted into this cache. For example, on a run, almost 5H (!) were needed before the first value was evicted from this cache. This mean this cache contains multiple states that do not share a lot of values with other states in all other caches/head.
==> A lot of fields stay in memory that are exclusively needed for the (old) states only present in this cache.
The beacon node now evicts finalized states from the cache.
Which issues(s) does this PR fix?
Acknowledgements