Skip to content

perf(gnoland): decode ante params once per committed height in CheckTx - #6460

Open
moul wants to merge 1 commit into
gnolang:masterfrom
moul:perf-checktx-params-cache
Open

moul wants to merge 1 commit into
gnolang:masterfrom
moul:perf-checktx-params-cache

Conversation

@moul

@moul moul commented Nov 6, 2026

Copy link
Copy Markdown
Member

Problem

The gno.land ante wrapper decodes the auth params (acck.GetParams) and the vm params
(vmk.GetParams plus ApplyToGasConfig) for every transaction it sees. Both amino-unmarshal
every field and bech32-decode every allowlist entry. Profiled with stage timers on a 5000-deep
mempool, the two decodes take about 305 us p50 (auth_params 148 us, vm_params 157 us), 37% of a
recheck
, more than the 31% spent on signature verification. With recheck on, every pending
transaction pays them again after every block, although CheckTx cannot see a params change
between two commits.

Change

  • gno.land/pkg/gnoland/anteparams.go: checkTxParams memoizes the decoded auth params, vm
    params and derived gas config for RunTxModeCheck, keyed on the CheckTx context's height.
  • app.go: the wrapper reads all three through it. The decode itself is moved verbatim into a
    closure; the order of reads relative to the gas meter is unchanged.
  • ADR: gno.land/adr/prxxxx_checktx_params_cache.md.

Invalidation

  • The key is the committed height. BaseApp replaces the check state only in InitChain, Commit
    and on load, each time with the header of the block just committed, and CheckTx runs the ante
    handler but never a message handler, so nothing writes params between two commits as CheckTx
    sees them. A params change made by a tx in block H reaches CheckTx through the check state of
    height H, which misses the entry for H-1.
  • A params change inside a block is never served stale: DeliverTx and simulate bypass the
    cache and decode on every call, as today, so the next tx of the same block sees the new value.
  • Genesis (height 0) always decodes.
  • The cached structs are shared and read-only; the only readers (the auth ante handler,
    checkCodePolicy, the gas config copy) do not mutate them.

Consensus: none

DeliverTx is untouched by construction. Both reads already bypass the gas meter, so skipping them
in CheckTx changes no gas. End to end below: identical app hash and identical gas.

In-tree benchmark

BenchmarkCheckTxRecheck (new, gno.land/pkg/gnoland/checktx_bench_test.go): one
CheckTx(Type: Recheck) of a bank send through the full app per iteration. Base is master with
only the benchmark file added; the two test binaries were run alternately, 8 rounds,
-test.benchtime 2000x, taskset -c 10-19, GOMAXPROCS=10, loadavg 20.33 at start, 17.12 at end.

                  │     base      │           pr-paramcache            │
                  │    sec/op     │   sec/op     vs base               │
CheckTxRecheck-10   1002.5µ ± 14%   602.6µ ± 6%  -39.89% (p=0.000 n=8)
                  │     B/op      │     B/op      vs base               │
CheckTxRecheck-10   185.04Ki ± 0%   75.58Ki ± 0%  -59.15% (p=0.000 n=8)
                  │  allocs/op  │  allocs/op   vs base               │
CheckTxRecheck-10   2.109k ± 0%   1.115k ± 0%  -47.13% (p=0.000 n=8)

End to end, mempool depth 5000

Same driver and method as PR 1 (real CListMempool, depth held at 5000, 100 tx per block, 10
blocks per run, master and branch alternated back to back on the same cores). Loadavg 16.95 at
start, 27.82 at end (09:28 to 09:35 UTC+1): the host got busier during rep 3.

run n blocks block p50 / p90 / p99 / stddev ms recheck p50 / p90 / p99 / stddev ms tx/s at block p50
master 1 10 5357.3 / 5505.4 / 5564.4 / 95.4 4392.5 / 4508.1 / 4552.7 / 72.1 18.67
branch 1 10 3851.6 / 3983.2 / 3983.7 / 86.6 2836.1 / 2965.0 / 2966.6 / 72.6 25.96
master 2 10 5447.0 / 5480.3 / 5494.7 / 58.9 4446.0 / 4540.5 / 4565.1 / 72.0 18.36
branch 2 10 4562.8 / 5128.7 / 5217.4 / 374.3 3398.0 / 3632.1 / 3736.6 / 218.6 21.92
master 3 10 5958.8 / 6135.7 / 6413.8 / 216.6 4852.9 / 5090.2 / 5279.8 / 209.0 16.78
branch 3 10 3978.1 / 4322.0 / 4334.2 / 162.7 2933.5 / 3182.0 / 3255.0 / 145.8 25.14

Paired, per rep: block p50 -28.1%, -16.2%, -33.2%: mean -25.9%, 95% CI -47.5% to -4.2%.
tx/s +39.1%, +19.4%, +49.8%: mean +36.1%, 95% CI -2.2% to +74.4%, which does not exclude zero
at n=3. Recheck p50 -35.4%, -23.6%, -39.6%. Branch rep 2 is the outlier (stddev 374 ms against
59 to 217 elsewhere, a noisy-neighbour signature); the benchstat above, at n=8, is the tighter
number.

Consensus check, identical in all six runs and identical to PR 1's runs: final app hash
CD51267EAF24E728DCA53B38EDDBED42088357B1DE19B40EF97BB4DC0AB41318, app-hash chain
43FD38708089B6A90D2013C346973F10658A913B666E96E4B52317F04C75CB30, DeliverTx gas 17,691,156,145,
CheckTx gas 34,990,311,192, 0 CheckTx failures.

Tests

TestCheckTxParams: CheckTx at one height decodes once; a change made in DeliverTx at the next
height is seen by DeliverTx at once (it never uses the cache) and by CheckTx once the height
moves; simulate never caches; height 0 never caches. Broken on purpose to see it fail: ignoring
the height fails it, caching in DeliverTx fails it.

$ go test ./gno.land/pkg/gnoland/ -count=1
ok  	github.com/gnolang/gno/gno.land/pkg/gnoland	24.167s

Out of scope

  • Caching in DeliverTx (needs a write hook in the params keeper and puts a cache on the consensus
    path).
  • gpk.LastGasPrice, also read per tx; small.
  • An app-level test that changes a param through governance and then rechecks; the invalidation is
    argued from BaseApp's check-state lifecycle and unit-tested on the cache.

AI-assisted: written with an AI coding agent and reviewed by the author; design notes in the ADR.

Signed-off-by: moul <94029+moul@users.noreply.github.com>
@Gno2D2

Gno2D2 commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: moul/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

This branch has not been deployed

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

Labels

📦 ⛰️ gno.land Issues or PRs gno.land package related

Projects

Status: 📥 Inbox

Development

Successfully merging this pull request may close these issues.

2 participants