Skip to content

Conversation

@yongkangc
Copy link
Member

@yongkangc yongkangc commented Dec 9, 2025

Problem

When proof tasks queue up in the worker pool (workers busy), each worker processes tasks one at a time. Multiple tasks for the same account result in redundant trie traversals.

Fixes #20088

Solution

Implement worker-level batching for both storage and account proofs:

  • When a worker receives a job, it drains additional queued jobs
  • Storage proof jobs for the same account are merged (prefix_sets and target_slots combined)
  • Account multiproof jobs are merged (targets and prefix_sets combined)
  • A single proof computation is performed for merged inputs
  • Results are sent to all original requestors

Changes

  • Add `BatchedStorageProof` struct to hold merged storage proof inputs
  • Add `BatchedAccountProof` struct to hold merged account multiproof inputs
  • Add `StorageWorkerBatchMetrics` and `AccountWorkerBatchMetrics` for tracking batch sizes
  • Modify `StorageProofWorker::run()` to batch consecutive storage proof jobs
  • Modify `AccountProofWorker::run()` to batch consecutive account multiproof jobs
  • Add `process_batched_storage_proof()` and `process_batched_account_multiproof()` functions
  • Add `Clone` derive to `ProofResult` for result sharing

Expected Impact

Reduced trie I/O and computation overhead when proof requests queue up, especially beneficial under high transaction throughput where state updates arrive faster than proof computation.

@yongkangc yongkangc added the C-perf A change motivated by improving speed, memory usage or disk footprint label Dec 9, 2025
@yongkangc yongkangc requested a review from Rjected as a code owner December 9, 2025 03:24
@yongkangc yongkangc added the A-trie Related to Merkle Patricia Trie implementation label Dec 9, 2025
@github-project-automation github-project-automation bot moved this to Backlog in Reth Tracker Dec 9, 2025
@yongkangc yongkangc marked this pull request as draft December 9, 2025 04:23
@yongkangc yongkangc changed the title perf(trie): batch storage proof jobs at worker level perf(trie): batch storage proof jobs at worker level (experiment) Dec 9, 2025
@yongkangc
Copy link
Member Author

github-actions bot and others added 15 commits December 9, 2025 11:32
Co-authored-by: Alexey Shekhirin <[email protected]>
Co-authored-by: Matthias Seitz <[email protected]>
Implement worker-level batching for both storage and account proofs to
reduce redundant trie traversals when multiple proof requests queue up.

When proof requests arrive faster than workers can process them, jobs
for the same account (storage proofs) or consecutive jobs (account proofs)
are now merged into single proof computations.
- Wrap DecodedMultiProof and DecodedStorageMultiProof in Arc within ProofResult
  for O(1) cloning when sending batched results to multiple receivers
- Add debug assertions in BatchedStorageProof::merge and BatchedAccountProof::merge
  to validate that all batched jobs share the same Arc for multi_added_removed_keys
  and missed_leaves_storage_roots (critical invariants for correctness)
- Unwrap Arc at extraction sites using try_unwrap for zero-cost when sole owner
- Change debug_assert to assert for multi_added_removed_keys Arc equality
  check in BatchedStorageProof::merge, ensuring incorrect proofs are
  caught in release builds, not just debug

- Change BatchedAccountProof::merge to try_merge returning Result, properly
  handling incompatible caches by processing as separate batches instead
  of panicking

- Add MAX_DEFERRED_BLINDED_NODES (16) limit to prevent starvation of
  blinded node requests under high proof load - stops batching early when
  limit reached

- Pre-allocate deferred_blinded_nodes vectors with capacity

- Remove unnecessary clone of storage_work_tx by taking reference
@yongkangc yongkangc closed this Dec 12, 2025
@github-project-automation github-project-automation bot moved this from Backlog to Done in Reth Tracker Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-trie Related to Merkle Patricia Trie implementation 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.

perf: Batch proof tasks at worker level

10 participants