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()andstorage_changeset_count()O(1) per static file by reading only the last committed.csoffrecord
cargo test -p reth-stages repro_collect_bottleneck_breakdown -- --ignored --nocaptureOptional 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- synthetic storage_v2 DB
- 200,000 historical blocks
- 1,000 blocks per static file
- 36-block live tail
- one account/storage changeset per block
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.
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.
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.
crates/stages/stages/src/stages/utils.rscrates/stages/stages/src/stages/index_storage_history.rscrates/storage/provider/src/providers/static_file/manager.rscrates/storage/provider/src/providers/static_file/mod.rs