Skip to content

[autoopt] 20260414-012-trie-exact-node-lookups - #23510

Closed
mediocregopher wants to merge 1 commit into
mainfrom
auto-opt/20260414-trie-exact-node-lookups
Closed

[autoopt] 20260414-012-trie-exact-node-lookups#23510
mediocregopher wants to merge 1 commit into
mainfrom
auto-opt/20260414-trie-exact-node-lookups

Conversation

@mediocregopher

Copy link
Copy Markdown
Member

Avoid rebuilding exact trie lookup pairs in changeset reads

Evidence

  • The baseline-1 samply profile shows the trie-input worker at 68,365 samples, with compute_trie_changesets at 67,228 inclusive samples, InMemoryTrieCursor::seek_exact at 64,955, and cursor_seek at 52,418.
  • The same thread spends large self time in node_key (21,595 samples), BranchNodeCompact decompression (2,691), and PackedStorageTrieEntry::from_compact (1,489), which is consistent with exact lookups doing extra key materialization around each hit.
  • crates/trie/trie/src/changesets.rs only needs the old node value, but seek_exact() returned a full (path, node) pair, forcing exact-hit cursor paths to rebuild keys that are immediately discarded.
  • This is distinct from the previously tried monotonic-seek and packed-decode directions: it keeps the lookup schedule unchanged and only trims unused exact-hit work.

Hypothesis

If we add an exact-hit cursor API that returns only the node and use it in trie changeset computation, gas throughput improves by ~0.2-0.5% because exact trie lookups avoid rebuilding keys that the changeset path never consumes.

Success Metric

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

Plan

  • Extend the trie cursor trait with seek_exact_node() and override it in the in-memory and database cursor implementations.
  • Switch account/storage changeset reads to the new API while preserving cursor metrics accounting.
  • Verify with cargo check -p reth-trie -p reth-trie-db, cargo test -p reth-trie changesets --lib, and targeted trie-db cursor tests.

@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

decofe commented Apr 14, 2026

Copy link
Copy Markdown
Member

cc @mediocregopher

✅ Benchmark complete! View job

Benchmark Results

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

Metric main auto-opt/20260414-trie-exact-node-lookups Change
Mean 34.71ms 33.96ms -2.16% ⚪ (±3.71%)
StdDev 29.81ms 29.60ms
P50 28.47ms 28.83ms +1.27% ⚪ (±3.05%)
P90 52.72ms 51.71ms -1.91% ⚪ (±9.69%)
P99 175.81ms 171.90ms -2.22% ⚪ (±30.04%)
Mgas/s 966.64 971.53 +0.51% ⚪ (±2.08%)
Wall Clock 14.26s 13.97s -2.02% ⚪ (±3.62%)

200 blocks, 100 warmup

Wait Time Breakdown

Persistence Wait

Metric main auto-opt/20260414-trie-exact-node-lookups
Mean 28.19ms 30.10ms
P50 0.02ms 0.02ms
P95 335.03ms 285.49ms

Trie Cache Update Wait

Metric main auto-opt/20260414-trie-exact-node-lookups
Mean 0.45ms 0.49ms
P50 0.00ms 0.00ms
P95 1.96ms 2.13ms

Execution Cache Update Wait

Metric main auto-opt/20260414-trie-exact-node-lookups
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

@github-project-automation github-project-automation Bot moved this from Backlog to Done in Reth Tracker Apr 15, 2026
@emmajam
emmajam deleted the auto-opt/20260414-trie-exact-node-lookups branch May 1, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants