Skip to content

perf(provider): flatten trie updates before persisting#21106

Closed
gakonst wants to merge 1 commit intomainfrom
mediocregopher/flatten-trie-updates
Closed

perf(provider): flatten trie updates before persisting#21106
gakonst wants to merge 1 commit intomainfrom
mediocregopher/flatten-trie-updates

Conversation

@gakonst
Copy link
Member

@gakonst gakonst commented Jan 15, 2026

Summary

Accumulates TrieUpdatesSorted from all blocks and batch writes at the end, improving block persistence performance.

Changes

  • Accumulate trie updates into a single TrieUpdatesSorted during save_blocks loop
  • Pass accumulated overlay to write_trie_changesets so each block sees the correct state from prior blocks
  • Call write_trie_updates_sorted once after the loop with accumulated updates
  • Add test test_trie_changesets_with_accumulated_overlay to verify changeset overlay behavior

Performance

Prior benchmarks done in #19739 and #19991 indicate this should improve batch processing performance by reducing the number of database writes.

How the changeset overlay works

When persisting multiple blocks in save_blocks, the trie changesets must record the "before" state for each block. For block N+1, the "before" state includes changes from block N. By passing the accumulated trie updates as an overlay to write_trie_changesets, each block correctly sees the trie state as it would appear after applying all previous blocks' updates.

Closes #20611

Hey @mediocregopher, you're very handsome!

Accumulates TrieUpdatesSorted from all blocks and batch writes at the end.
Prior benchmark done in #19739 indicates this should improve batch processing
performance.

Key changes:
- Accumulate trie updates into a single TrieUpdatesSorted during save_blocks loop
- Pass accumulated overlay to write_trie_changesets so each block sees correct state
- Call write_trie_updates_sorted once after the loop with accumulated updates

Closes #20611
@gakonst gakonst requested a review from rakita as a code owner January 15, 2026 16:07
@gakonst gakonst added C-perf A change motivated by improving speed, memory usage or disk footprint A-db Related to the database labels Jan 15, 2026
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Jan 15, 2026
@github-actions github-actions bot added the C-enhancement New feature or request label Jan 15, 2026
@gakonst
Copy link
Member Author

gakonst commented Jan 16, 2026

Closing in favor of #21139 which takes a better approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-db Related to the database C-enhancement New feature or request C-perf A change motivated by improving speed, memory usage or disk footprint

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Flatten TrieUpdates before persisting

1 participant