Skip to content

perf(vm): avoid duplicate LockedCoins read in GetAccount#1203

Open
0u-Y wants to merge 1 commit into
cosmos:mainfrom
0u-Y:perf/getaccount-dedup-locked
Open

perf(vm): avoid duplicate LockedCoins read in GetAccount#1203
0u-Y wants to merge 1 commit into
cosmos:mainfrom
0u-Y:perf/getaccount-dedup-locked

Conversation

@0u-Y

@0u-Y 0u-Y commented Jun 6, 2026

Copy link
Copy Markdown

Description

GetAccount computed spendable and locked via separate SpendableCoin and
lockedCoin calls, each reading LockedCoins from the bank store — so every
GetAccount read LockedCoins twice. This reads balance and LockedCoins
once in a new spendableAndLockedCoin helper and derives both; the now-unused
lockedCoin is removed.

Equivalence

  • locked: LockedCoins(addr).AmountOf(evmDenom) — unchanged.
  • spendable: balance.SubAmount(locked) on the sdk.Coin from
    bankWrapper.GetBalance, identical to what bankWrapper.SpendableCoin
    computes (same sdk.Coin.SubAmount, same panic-on-negative).

validateCoinInfo enforces Denom == ExtendedDenom + 18 decimals, so
AmountOf(evmDenom) == AmountOf(extendedDenom); the values and the #1187
locked-snapshot semantics are preserved.

Benchmarks

Transfer-saturated block, local harness (not in-tree, happy to share),
2000 txs/block, -benchtime=10x -count=6, Ryzen 9 7900 (n=6):

benchmark sec/op B/op allocs/op
Sequential 677.5m → 661.8m (−2.32%, p=0.004) 393.3Mi → 380.5Mi (−3.26%) 6.030M → 5.758M (−4.51%)
BlockSTM 206.5m → 209.6m (~, p=0.82) 464.5Mi → 452.3Mi (−2.63%) 6.954M → 6.692M (−3.77%)

p=0.002 unless noted. Allocations drop significantly on both paths; serial
wall-time −2.3%; Block-STM wall-time is within noise. Workload-dependent —
smaller for contract-heavy blocks.

Tests

TestKeeperTestSuite (StateDB balance suite) and the staking-precompile suite
(#1187 locked-via-precompile guard) pass unchanged.

The merged helper no longer opens the SpendableCoin/LockedCoin tracing
sub-spans (the parent GetAccount span is unchanged).

Closes: #1202


Author Checklist

I have...

Signed-off-by: 0u-Y <yyw1000@naver.com>
@0u-Y 0u-Y requested a review from a team as a code owner June 6, 2026 20:55
@greptile-apps

greptile-apps Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

PR author is not in the allowed authors list.

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.

GetAccount performs a redundant LockedCoins read

1 participant