Skip to content

Periodically evict finalized states in checkpoint states cache#16458

Merged
nalepae merged 2 commits intodevelopfrom
checkpoint-state-cache
Mar 6, 2026
Merged

Periodically evict finalized states in checkpoint states cache#16458
nalepae merged 2 commits intodevelopfrom
checkpoint-state-cache

Conversation

@nalepae
Copy link
Contributor

@nalepae nalepae commented Mar 3, 2026

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?

image

Acknowledgements

  • I have read CONTRIBUTING.md.
  • I have included a uniquely named changelog fragment file.
  • I have added a description with sufficient context for reviewers to understand this PR.
  • I have tested that my changes work as expected and I added a testing plan to the PR description (if applicable).

@nalepae nalepae changed the title Checkpoint state cache Remove checkpoint state cache Mar 3, 2026
@nalepae nalepae force-pushed the checkpoint-state-cache branch from 44c05d5 to 86e0c43 Compare March 4, 2026 10:08
@nalepae nalepae changed the title Remove checkpoint state cache Add TTL to checkpoint state cache Mar 4, 2026
@nalepae nalepae marked this pull request as ready for review March 4, 2026 15:26
@nalepae nalepae added the optimization PR making Prysm more effective label Mar 4, 2026
@nalepae nalepae force-pushed the checkpoint-state-cache branch from 86e0c43 to 16123a5 Compare March 5, 2026 16:33
@nalepae nalepae changed the title Add TTL to checkpoint state cache Periodically evict finalized states in checkpoint states cache Mar 5, 2026
@nalepae nalepae force-pushed the checkpoint-state-cache branch from 16123a5 to 2a4cb08 Compare March 5, 2026 16:34
@nalepae nalepae force-pushed the checkpoint-state-cache branch from 2a4cb08 to 23c20d1 Compare March 5, 2026 16:53
go s.runLateBlockTasks()
}

// spawnCheckpointStateCacheEvictionRoutine runs a background goroutine that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need this extra routine? you're in the blockchain package, just hook it onto executePostFinalizationTasks or similar.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in e953d89.

@nalepae nalepae added this pull request to the merge queue Mar 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 6, 2026
@nalepae nalepae added this pull request to the merge queue Mar 6, 2026
Merged via the queue into develop with commit 3ec505b Mar 6, 2026
19 checks passed
@nalepae nalepae deleted the checkpoint-state-cache branch March 6, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimization PR making Prysm more effective

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants