Skip to content

Conversation

@dhyaniarun1993
Copy link
Collaborator

@dhyaniarun1993 dhyaniarun1993 commented Jan 8, 2026

Closes #562

Validated the optimization by rewriting an initial state with N=50,000 updated entries.

  • Throughput: Increased by ~20.9% (326k → 394k entries/sec).
  • Latency: Reduced by ~17.2% (153ms → 126ms).
Old approach:
Rewrite Duration: 153.26ms
Throughput:       326,248 entries/sec

New approach:
Rewrite Duration: 126.77ms
Throughput:       394,410 entries/sec

bench: 180e132

@dhyaniarun1993 dhyaniarun1993 self-assigned this Jan 8, 2026
@dhyaniarun1993 dhyaniarun1993 added A-pruning Area: pruning W-historical-proofs Workstream: historical-proofs labels Jan 8, 2026
@codecov
Copy link

codecov bot commented Jan 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 38.45%. Comparing base (e21a30b) to head (3c59600).

Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
crates/optimism/trie/src/db/store.rs 98.17% <100.00%> (-0.04%) ⬇️
crates/optimism/trie/src/prune/pruner.rs 95.18% <100.00%> (ø)

... and 19 files with indirect coverage changes

Flag Coverage Δ
e2e 35.86% <92.30%> (+0.21%) ⬆️
unit 26.89% <92.30%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
reth binary 53.14% <ø> (ø)
op historical proof 89.93% <100.00%> (-0.02%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dhyaniarun1993 dhyaniarun1993 changed the title feat: optimised initial state update for pruning feat: optimised initial state update for pruning [WIP] Jan 8, 2026
@dhyaniarun1993 dhyaniarun1993 changed the title feat: optimised initial state update for pruning [WIP] feat: optimised initial state update for pruning Jan 9, 2026
@dhyaniarun1993 dhyaniarun1993 marked this pull request as ready for review January 9, 2026 10:43
Copilot AI review requested due to automatic review settings January 9, 2026 10:43
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR optimizes the initial state update operation during pruning, achieving approximately 20.9% throughput improvement and 17.2% latency reduction. The optimization restructures the database write strategy from an interleaved approach to a more efficient two-phase sequential approach.

Key changes:

  • Restructured prune mode database operations to use sequential batch deletion followed by batch writes instead of interleaved operations
  • Corrected timing measurement to include all fetch operations (trie updates and block hashes) in the reported fetch duration

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
crates/optimism/trie/src/prune/pruner.rs Moved fetch_duration measurement to after block hash fetches for accurate timing attribution
crates/optimism/trie/src/db/store.rs Refactored persist_history_batch prune mode logic to use two-phase approach: batch delete all block 0 entries, then batch write non-tombstones

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@emhane emhane left a comment

Choose a reason for hiding this comment

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

lgtm

Comment on lines +164 to +165
// Drop current cursor to start clean for Phase 1
drop(cur);
Copy link
Member

Choose a reason for hiding this comment

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

nice

Comment on lines +167 to +168
// Phase 1: Batch Delete (Sequential)
// Remove all existing state at Block 0 for these keys.
Copy link
Member

Choose a reason for hiding this comment

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

thank you for the numbered steps in these code comments, improves readability

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

Labels

A-pruning Area: pruning W-historical-proofs Workstream: historical-proofs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

optimize initial state update in pruning

3 participants