Skip to content

[autoopt] 20260414-008-sparse-prune-retained-slices#23508

Draft
mediocregopher wants to merge 1 commit intomainfrom
auto-opt/20260414-sparse-prune-retained-slices
Draft

[autoopt] 20260414-008-sparse-prune-retained-slices#23508
mediocregopher wants to merge 1 commit intomainfrom
auto-opt/20260414-sparse-prune-retained-slices

Conversation

@mediocregopher
Copy link
Copy Markdown
Member

Reuse sorted retained leaves during sparse-trie pruning

Evidence

  • The baseline samply profile shows reth_trie_sparse::arena::ArenaSparseSubtrie::prune with 6,150 exclusive samples on the sparse-trie maintenance path.
  • SparseStateTrie::prune already computes one LFU-selected retained set for the whole prune pass, but the arena and parallel trie implementations each cloned and re-sorted retained_leaves again inside every prune call.
  • The hot internal caller already supplies sorted per-address slot lists from retained_slots_by_address, so most of that clone/sort work was avoidable bookkeeping rather than trie logic.

Hypothesis

If we sort retained account leaves once in SparseStateTrie::prune and let sparse-trie prune implementations borrow already sorted slices instead of cloning them, gas throughput improves by ~0.2-0.6% because sparse-trie pruning does less repeated leaf-list allocation and sorting on the hot cache-maintenance path.

Success Metric

  • gas_per_second (mgas_s.pct in summary.json) improves by >0.2%

Plan

  • Sort account LFU retention once in crates/trie/sparse/src/state.rs.
  • Update crates/trie/sparse/src/arena/mod.rs and crates/trie/sparse/src/parallel.rs to borrow sorted retained_leaves when possible and only allocate on unsorted fallback inputs.
  • Verify with cargo check -p reth-trie-sparse and cargo test -p reth-trie-sparse prune --lib.

@mediocregopher
Copy link
Copy Markdown
Member Author

derek bench

@github-actions
Copy link
Copy Markdown
Contributor

Your PR title doesn't follow the Conventional Commit guidelines.

Example of valid titles:

  • feat: add new user login
  • fix: correct button size
  • docs: update README

Usage:

  • feat: Introduces a new feature
  • fix: Patches a bug
  • chore: General maintenance tasks or updates
  • test: Adding new tests or modifying existing tests
  • bench: Adding new benchmarks or modifying existing benchmarks
  • perf: Performance improvements
  • refactor: Changes to improve code structure
  • docs: Documentation updates
  • ci: Changes to CI/CD configurations
  • revert: Reverts a previously merged PR
  • deps: Updates dependencies

Breaking Changes

Breaking changes are noted by using an exclamation mark. For example:

  • feat!: changed the API
  • chore(node)!: Removed unused public function

Help

For more information, follow the guidelines here: https://www.conventionalcommits.org/en/v1.0.0/

@decofe
Copy link
Copy Markdown
Member

decofe commented Apr 14, 2026

cc @mediocregopher

✅ Benchmark complete! View job

Benchmark Results

⚠️ Feature is 1 commit behind main. Consider rebasing for accurate results.

Metric main auto-opt/20260414-sparse-prune-retained-slices Change
Mean 34.09ms 34.37ms +0.81% ⚪ (±3.18%)
StdDev 30.01ms 31.22ms
P50 28.05ms 28.33ms +1.02% ⚪ (±3.29%)
P90 51.94ms 52.01ms +0.13% ⚪ (±9.48%)
P99 200.57ms 204.56ms +1.99% ⚪ (±17.66%)
Mgas/s 969.22 980.48 +1.16% ⚪ (±2.03%)
Wall Clock 14.04s 14.14s +0.69% ⚪ (±3.13%)

200 blocks, 100 warmup

Wait Time Breakdown

Persistence Wait

Metric main auto-opt/20260414-sparse-prune-retained-slices
Mean 27.18ms 28.22ms
P50 0.03ms 0.03ms
P95 307.96ms 305.78ms

Trie Cache Update Wait

Metric main auto-opt/20260414-sparse-prune-retained-slices
Mean 0.44ms 0.24ms
P50 0.00ms 0.00ms
P95 2.07ms 1.08ms

Execution Cache Update Wait

Metric main auto-opt/20260414-sparse-prune-retained-slices
Mean 0.01ms 0.00ms
P50 0.00ms 0.00ms
P95 0.00ms 0.00ms

Grafana Dashboard

Charts

Latency, Throughput & Diff

Latency, Throughput & Diff

Wait Time Breakdown

Wait Time Breakdown

Gas vs Latency

Gas vs Latency

Grafana Dashboard

View real-time metrics

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

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

2 participants