Skip to content

bank: sdk.Int object pool to reduce allocations in balance reads#3373

Merged
codchen merged 1 commit into
mainfrom
tony/object-pool
May 5, 2026
Merged

bank: sdk.Int object pool to reduce allocations in balance reads#3373
codchen merged 1 commit into
mainfrom
tony/object-pool

Conversation

@codchen

@codchen codchen commented May 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Introduces SdkIntPool (backed by sync.Pool) on BaseViewKeeper, stored as intPool *SdkIntPool
  • sdk.Int.Unmarshal already reuses the existing *big.Int when non-nil, so a pooled entry skips the big.Int allocation on subsequent unmarshal calls
  • All direct sdk.Int storage reads in the bank keeper (GetWeiBalance, GetSupply, GetPaginatedTotalSupply, IterateAllWeiBalances, IterateTotalSupply) now borrow from the pool instead of allocating fresh per call
  • Iterator paths borrow a single pool entry for the entire iteration — one big.Int allocation total instead of 2N; callbacks that need to retain the value past the callback must copy via i.BigInt() (documented in the IterateAllWeiBalances comment)
  • genesis.go's IterateAllWeiBalances callback, which stores values into a slice, is updated to call sdk.NewIntFromBigInt(i.BigInt()) for an explicit deep copy

Test plan

  • Existing sei-cosmos/x/bank/keeper unit tests pass (go test ./sei-cosmos/x/bank/keeper/...)
  • Verify genesis export round-trip (wei balances are not corrupted)
  • Run invariant checks to confirm IterateAllWeiBalances still produces correct totals

🤖 Generated with Claude Code

Introduces SdkIntPool (backed by sync.Pool) on BaseViewKeeper and uses it
across all direct sdk.Int storage reads. sdk.Int.Unmarshal already reuses
the existing *big.Int when non-nil, so pooled entries skip the big.Int
allocation on subsequent unmarshal calls. Iterator paths (IterateAllWeiBalances,
IterateTotalSupply, GetPaginatedTotalSupply) now borrow a single pool entry for
the whole iteration instead of allocating per entry; callbacks that store the
value must copy via i.BigInt(), which genesis.go now does explicitly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions

github-actions Bot commented May 4, 2026

Copy link
Copy Markdown

The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed✅ passedMay 4, 2026, 4:10 AM

@codecov

codecov Bot commented May 4, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 77.77778% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.17%. Comparing base (6620fb6) to head (2ec955d).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
sei-cosmos/x/bank/keeper/keeper.go 69.23% 1 Missing and 3 partials ⚠️
sei-cosmos/x/bank/keeper/view.go 63.63% 1 Missing and 3 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #3373   +/-   ##
=======================================
  Coverage   59.17%   59.17%           
=======================================
  Files        2097     2098    +1     
  Lines      172641   172659   +18     
=======================================
+ Hits       102163   102179   +16     
- Misses      61615    61617    +2     
  Partials     8863     8863           
Flag Coverage Δ
sei-chain-pr 78.19% <77.77%> (?)
sei-db 70.41% <ø> (ø)

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

Files with missing lines Coverage Δ
sei-cosmos/x/bank/keeper/genesis.go 76.59% <100.00%> (ø)
sei-cosmos/x/bank/keeper/pool.go 100.00% <100.00%> (ø)
sei-cosmos/x/bank/keeper/keeper.go 79.93% <69.23%> (-0.19%) ⬇️
sei-cosmos/x/bank/keeper/view.go 85.71% <63.63%> (-0.26%) ⬇️
🚀 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.

@codchen codchen added this pull request to the merge queue May 5, 2026
Merged via the queue into main with commit cb91c34 May 5, 2026
43 of 44 checks passed
@codchen codchen deleted the tony/object-pool branch May 5, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants