Skip to content

Instantly share code, notes, and snippets.

@yongkangc
Last active March 31, 2026 04:29
Show Gist options
  • Select an option

  • Save yongkangc/06d1da54a32b4a1818c9432483fef7a6 to your computer and use it in GitHub Desktop.

Select an option

Save yongkangc/06d1da54a32b4a1818c9432483fef7a6 to your computer and use it in GitHub Desktop.
storage_v2 history stage repro and before/after timings

storage_v2 history stage repro

Manual repro for the storage_v2 account/storage history stage bottleneck and the combined fix:

  • remove the full-history count pre-pass from the live-tail history stage path
  • make account_changeset_count() and storage_changeset_count() O(1) per static file by reading only the last committed .csoff record

Command

cargo test -p reth-stages repro_collect_bottleneck_breakdown -- --ignored --nocapture

Optional scaling knobs:

RETH_HISTORY_REPRO_BLOCKS=200000 \
RETH_HISTORY_REPRO_BLOCKS_PER_FILE=1000 \
cargo test -p reth-stages repro_collect_bottleneck_breakdown -- --ignored --nocapture

Setup

  • synthetic storage_v2 DB
  • 200,000 historical blocks
  • 1,000 blocks per static file
  • 36-block live tail
  • one account/storage changeset per block

Before Any Fix

storage_v2 history repro: blocks=200000 blocks_per_file=1000 tail_blocks=36 account_changesets=200000 storage_changesets=200000 account_count=33.419738ms storage_count=35.809299ms account_walk=375.696µs storage_walk=250.841µs account_stage=35.210574ms storage_stage=35.555372ms

The stage time closely tracked the full-history .csoff count probes, while the requested tail walks were tiny.

After Stage Fix Only

storage_v2 history repro: blocks=200000 blocks_per_file=1000 tail_blocks=36 account_changesets=200000 storage_changesets=200000 account_count=32.905226ms storage_count=32.733914ms account_walk=333.376µs storage_walk=250.601µs account_probe=33.238602ms storage_probe=32.984515ms account_stage=1.513895ms storage_stage=2.702298ms account_stage_minus_probe=0ns storage_stage_minus_probe=0ns

The hot path no longer paid the full-history count, but the standalone count helpers were still expensive.

After Adding the Count Helper Optimization

storage_v2 history repro: blocks=200000 blocks_per_file=1000 tail_blocks=36 account_changesets=200000 storage_changesets=200000 account_count=2.656805ms storage_count=2.595731ms account_walk=275.885µs storage_walk=241.741µs account_probe=2.93269ms storage_probe=2.837472ms account_stage=1.599389ms storage_stage=2.427516ms account_stage_minus_probe=0ns storage_stage_minus_probe=0ns

This keeps the live-tail stage fast and also makes the count helpers themselves much cheaper for any remaining callers.

Files

  • crates/stages/stages/src/stages/utils.rs
  • crates/stages/stages/src/stages/index_storage_history.rs
  • crates/storage/provider/src/providers/static_file/manager.rs
  • crates/storage/provider/src/providers/static_file/mod.rs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment