Skip to content

perf(rpc): avoid IndexedBatch allocation in read-only state views - #3941

Draft
thiagodeev wants to merge 2 commits into
mainfrom
perf/getNonce
Draft

perf(rpc): avoid IndexedBatch allocation in read-only state views#3941
thiagodeev wants to merge 2 commits into
mainfrom
perf/getNonce

Conversation

@thiagodeev

@thiagodeev thiagodeev commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Read-only state views (HeadState, StateAtBlockNumber, StateAtBlockHash) in deprecatedStateBackend previously allocated a Pebble IndexedBatch per call, paying the batch setup cost and the batch-overlay merge on every subsequent Get - despite never writing. They now read the database directly through a readOnlyTxn adapter that satisfies the db.IndexedBatch interface deprecatedstate.New requires but rejects writes.

Also adds BenchmarkNonce, benchmarking Handler.Nonce against a real Pebble-backed state with 50k contracts under pseudorandom addresses.

Numbers

BenchmarkNonce, benchstat over 6 runs each (-benchtime=2s):

metric main this PR delta
time/op 4.184us +-7% 3.392us +-4% -18.92%
B/op 2031 374 -81.59%
allocs/op 19 12 -36.84%

Every read-only RPC that goes through these state views benefits, not just starknet_getNonce.

@thiagodeev thiagodeev added the disable-deploy-test We don't want to run deploy tests with this PR because it might affect our development environment. label Aug 13, 2026
@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 62.50000% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.51%. Comparing base (d5d68c0) to head (0d237a9).

Files with missing lines Patch % Lines
blockchain/statebackend/deprecated.go 50.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3941      +/-   ##
==========================================
- Coverage   74.63%   74.51%   -0.13%     
==========================================
  Files         462      462              
  Lines       40989    40990       +1     
==========================================
- Hits        30592    30543      -49     
- Misses       8294     8347      +53     
+ Partials     2103     2100       -3     
Flag Coverage Δ
jsonv2 77.36% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@thiagodeev thiagodeev changed the title Perf/getNonce perf(rpc): avoid IndexedBatch allocation in read-only state views Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disable-deploy-test We don't want to run deploy tests with this PR because it might affect our development environment.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant