Skip to content

perf(state): bypass write buffer for read-only state requests - #784

Merged
ValarDragon merged 8 commits into
mainfrom
perf/state-read-routing
Aug 27, 2026
Merged

perf(state): bypass write buffer for read-only state requests#784
ValarDragon merged 8 commits into
mainfrom
perf/state-read-routing

Conversation

@evan-forbes

@evan-forbes evan-forbes commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Motivation

The transaction verifier and mempool send read-only requests through the
serialized read-write state buffer. The read-write service immediately forwards
those requests to the existing read service.

The preserved 80-node campaign observed 12,589,364 requests through the outer
buffer. These changes can bypass that buffer for at least 7,868,996 requests.
The upper bound is 12,142,479 requests, or 96.45% of observed traffic.

The request count measures removed buffer work. It does not establish a latency
saving.

Solution

  • Route transaction-verifier nullifier, anchor, median-time-past, and best-chain
    UTXO reads directly to ReadStateService.
  • Keep block AwaitUtxo requests and every write on the read-write service.
  • Route mempool best-chain transaction and tip reads directly to
    ReadStateService.
  • Retain the read-write state handle as a mempool lifetime guard.
  • Add routing tests that prove read-only and waiting requests reach the correct
    service.
  • Assert that the mempool never sends requests through the retained write-state
    guard.
  • Remove mempool read concurrency from the write-state buffer budget.

Safety

The read-write state service already forwards these request variants to a clone
of the same read service. The change removes one outer buffer hop. It does not
change the query implementation, non-finalized snapshot source, request bounds,
or write ownership.

The routed requests stop incrementing the outer service="state" request
series. The existing service="read_state" series continues to count them.
Block AwaitUtxo readiness now falls inside the transaction-verifier timeout.

Results

The release benchmark sends 100,000 sequential median-time-past reads per
sample. It wraps the production TransactionStateRouter in a bound-one Tower
buffer for the baseline. The direct arm uses the same router and fixed response
without that buffer. Five invocations collected ten samples per arm.

Route Median latency per request
Buffered 3.622 us
Direct 0.054 us
Removed dispatch 3.568 us (98.5%)

This unloaded benchmark isolates dispatch. It does not include state query work
or CPU saturation. The preserved fleet counts show how often the node removes
the hop. They do not convert the unloaded result into an end-to-end latency
claim.

Validation

  • cargo bench -p zakura-consensus --bench state_read_routing --features internal-bench
  • cargo test -p zakura-consensus --lib --locked: passed
  • cargo test -p zakura --lib --locked: 405 passed; one baseline test failed
  • cargo clippy -p zakura-chain -p zakura-consensus -p zakura-state -p zakura --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

The baseline failure is
inbound_pruned_block_is_not_advertised_and_getdata_logs_error. The focused
test also fails on untouched main.

Changelog

This PR adds docs/changelog/unreleased/784.md.

Stack

@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from a66e320 to ce7eaf6 Compare August 23, 2026 05:53
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from dfc104e to 34a2683 Compare August 23, 2026 05:53
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from ce7eaf6 to 91c7ce2 Compare August 23, 2026 08:11
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from 34a2683 to 9331437 Compare August 23, 2026 08:11
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from 91c7ce2 to 8a61e72 Compare August 23, 2026 16:46
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from 9331437 to c98987d Compare August 23, 2026 16:46
@evan-forbes
evan-forbes marked this pull request as ready for review August 23, 2026 17:28
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from c98987d to c0b4b50 Compare August 23, 2026 17:45
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from 8a61e72 to 09a498a Compare August 23, 2026 17:45
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from c0b4b50 to eacd326 Compare August 23, 2026 18:42
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch 2 times, most recently from 7de3197 to d555395 Compare August 23, 2026 18:52
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from eacd326 to c4c0002 Compare August 23, 2026 18:52
@evan-forbes
evan-forbes force-pushed the perf/contextual-phase-metrics branch from d555395 to abc601b Compare August 23, 2026 19:38
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from c4c0002 to 8893ea8 Compare August 23, 2026 19:38
@evan-forbes
evan-forbes changed the base branch from perf/contextual-phase-metrics to main August 23, 2026 19:38
@evan-forbes
evan-forbes force-pushed the perf/state-read-routing branch from 8893ea8 to 767fa08 Compare August 23, 2026 19:41

@ValarDragon ValarDragon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Nice job on this

@ValarDragon
ValarDragon merged commit f940aad into main Aug 27, 2026
47 checks passed
@ValarDragon
ValarDragon deleted the perf/state-read-routing branch August 27, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants