Skip to content

perf(db): flatten HashedPostState before persisting#21422

Merged
mattsse merged 1 commit intomainfrom
flatten-hashed-post-state
Jan 26, 2026
Merged

perf(db): flatten HashedPostState before persisting#21422
mattsse merged 1 commit intomainfrom
flatten-hashed-post-state

Conversation

@gakonst
Copy link
Member

@gakonst gakonst commented Jan 26, 2026

Summary

Accumulate hashed state from all blocks using HashedPostStateSorted::merge_batch and write it in a single batch, reducing cursor open/close overhead from N calls to 1.

This mirrors the existing optimization for trie updates (which was already batched).

Changes

  • Move write_hashed_state call outside the per-block loop
  • Use HashedPostStateSorted::merge_batch to combine all hashed states (newest-to-oldest)
  • Write the merged hashed state in a single operation

Closes #20609

Accumulate hashed state from all blocks using `HashedPostStateSorted::merge_batch`
and write it in a single batch, reducing cursor open/close overhead from N calls to 1.

This mirrors the existing optimization for trie updates.

Closes #20609
@gakonst gakonst added C-perf A change motivated by improving speed, memory usage or disk footprint A-db Related to the database labels Jan 26, 2026
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Jan 26, 2026
@github-actions github-actions bot added the C-enhancement New feature or request label Jan 26, 2026
@mediocregopher
Copy link
Member

## Commits
- **Baseline**: afe164b (main)
- **Feature**: 76a8ed0 (flatten-hashed-post-state)

## Results

| Metric | Baseline | Feature | Change |
|--------|----------|---------|--------|
| Mean Latency | 37.89ms | 37.36ms | -1.39% ≈ |
| Std Dev | 24.23ms | 23.98ms | |
| P50 Latency | 30.09ms | 29.76ms | -1.11% ≈ |
| P90 Latency | 69.32ms | 66.38ms | -4.23% |
| P99 Latency | 138.29ms | 135.17ms | -2.26% |
| Gas/sec | 792.98 Mgas/s | 804.13 Mgas/s | 1.41% ≈ |```

@mediocregopher mediocregopher marked this pull request as ready for review January 26, 2026 10:56
Copy link
Member

@yongkangc yongkangc left a comment

Choose a reason for hiding this comment

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

nice, didnt know that reducing cursor overhead would be so big

@github-project-automation github-project-automation bot moved this from Backlog to In Progress in Reth Tracker Jan 26, 2026
@mattsse mattsse added this pull request to the merge queue Jan 26, 2026
Merged via the queue into main with commit 71ed68e Jan 26, 2026
46 checks passed
@mattsse mattsse deleted the flatten-hashed-post-state branch January 26, 2026 22:57
@github-project-automation github-project-automation bot moved this from In Progress to Done in Reth Tracker Jan 26, 2026
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 HashedPostState before persisting

4 participants