bank: sdk.Int object pool to reduce allocations in balance reads#3373
Merged
Conversation
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>
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
sei-will
approved these changes
May 4, 2026
philipsu522
approved these changes
May 4, 2026
arajasek
approved these changes
May 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SdkIntPool(backed bysync.Pool) onBaseViewKeeper, stored asintPool *SdkIntPoolsdk.Int.Unmarshalalready reuses the existing*big.Intwhen non-nil, so a pooled entry skips thebig.Intallocation on subsequent unmarshal callssdk.Intstorage reads in the bank keeper (GetWeiBalance,GetSupply,GetPaginatedTotalSupply,IterateAllWeiBalances,IterateTotalSupply) now borrow from the pool instead of allocating fresh per callbig.Intallocation total instead of 2N; callbacks that need to retain the value past the callback must copy viai.BigInt()(documented in theIterateAllWeiBalancescomment)genesis.go'sIterateAllWeiBalancescallback, which stores values into a slice, is updated to callsdk.NewIntFromBigInt(i.BigInt())for an explicit deep copyTest plan
sei-cosmos/x/bank/keeperunit tests pass (go test ./sei-cosmos/x/bank/keeper/...)IterateAllWeiBalancesstill produces correct totals🤖 Generated with Claude Code