diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ac76b5e86e..fe7d4602743 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,7 +52,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Misc Improvements * [#7106](https://github.com/osmosis-labs/osmosis/pull/7106) Halve the time of log2 calculation (speeds up TWAP code) -* [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100) Lower CPU overheads of the Osmosis epoch. +* [#7093](https://github.com/osmosis-labs/osmosis/pull/7093),[#7100](https://github.com/osmosis-labs/osmosis/pull/7100),[#7172](https://github.com/osmosis-labs/osmosis/pull/7093) Lower CPU overheads of the Osmosis epoch. ## v21.0.0 diff --git a/x/lockup/types/lock.go b/x/lockup/types/lock.go index fc3edce6691..ad1d5006297 100644 --- a/x/lockup/types/lock.go +++ b/x/lockup/types/lock.go @@ -2,6 +2,7 @@ package types import ( "fmt" + "math/big" "strings" "time" @@ -63,18 +64,25 @@ func (p PeriodLock) SingleCoin() (sdk.Coin, error) { } // TODO: Can we use sumtree instead here? +// Assumes that caller is passing in locks that contain denom func SumLocksByDenom(locks []PeriodLock, denom string) osmomath.Int { - sum := osmomath.NewInt(0) + sumBi := big.NewInt(0) // validate the denom once, so we can avoid the expensive validate check in the hot loop. err := sdk.ValidateDenom(denom) if err != nil { panic(fmt.Errorf("invalid denom used internally: %s, %v", denom, err)) } for _, lock := range locks { - // TODO: Replace with Mutative Int Operations - sum = sum.Add(lock.Coins.AmountOfNoDenomValidation(denom)) + var amt osmomath.Int + // skip a 1second cumulative runtimeEq check + if len(lock.Coins) == 1 { + amt = lock.Coins[0].Amount + } else { + amt = lock.Coins.AmountOfNoDenomValidation(denom) + } + sumBi.Add(sumBi, amt.BigIntMut()) } - return sum + return osmomath.NewIntFromBigInt(sumBi) } // quick fix for getting native denom from synthetic denom.