Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
types: make chopPrecisionAndTruncate always non-mutative (#9250)
Currently, chopPrecisionAndTruncate/chopPrecisionAndTruncateNonMutative are doing the same thing, except that the former do it mutatively. Looking at the usages of chopPrecisionAndTruncate, the callers must alloc a new big.Int before calling it anyway, so any mutation will be done with this new allocated big.Int, instead of input argument. So, by making chopPrecisionAndTruncate always non-mutative, we simplify the code, and make the code faster, less allocation in some benchmarks. Benchmark for github.com/cosmos/cosmos-sdk/types: name old time/op new time/op delta CoinsAdditionIntersect/sizes:_A_1,_B_1-8 35.4ns ± 0% 35.1ns ± 0% -0.92% (p=0.008 n=5+5) CoinsAdditionIntersect/sizes:_A_5,_B_5-8 366ns ± 1% 363ns ± 1% ~ (p=0.056 n=5+5) CoinsAdditionIntersect/sizes:_A_5,_B_20-8 557ns ± 0% 553ns ± 0% -0.64% (p=0.008 n=5+5) CoinsAdditionIntersect/sizes:_A_1,_B_1000-8 6.17µs ± 0% 6.18µs ± 0% ~ (p=0.151 n=5+5) CoinsAdditionIntersect/sizes:_A_2,_B_1000-8 6.30µs ± 0% 6.32µs ± 0% +0.23% (p=0.008 n=5+5) CoinsAdditionNoIntersect/sizes:_A_1,_B_1-8 30.2ns ± 0% 29.9ns ± 1% -0.98% (p=0.008 n=5+5) CoinsAdditionNoIntersect/sizes:_A_5,_B_5-8 226ns ± 0% 224ns ± 0% -0.54% (p=0.008 n=5+5) CoinsAdditionNoIntersect/sizes:_A_5,_B_20-8 373ns ± 0% 372ns ± 0% -0.26% (p=0.040 n=5+5) CoinsAdditionNoIntersect/sizes:_A_1,_B_1000-8 6.21µs ± 0% 6.22µs ± 0% ~ (p=0.421 n=5+5) CoinsAdditionNoIntersect/sizes:_A_2,_B_1000-8 6.22µs ± 0% 6.23µs ± 0% ~ (p=0.286 n=5+5) CoinsAdditionNoIntersect/sizes:_A_1000,_B_2-8 6.22µs ± 0% 6.23µs ± 0% ~ (p=0.143 n=5+5) ParseCoin-8 5.46µs ± 0% 5.39µs ± 0% -1.26% (p=0.008 n=5+5) UintMarshal-8 1.01µs ± 0% 1.00µs ± 0% -1.10% (p=0.008 n=5+5) IntMarshal-8 764ns ± 0% 758ns ± 1% -0.79% (p=0.024 n=5+5) MarshalTo-8 192ns ± 0% 190ns ± 0% -1.03% (p=0.008 n=5+5) name old alloc/op new alloc/op delta CoinsAdditionIntersect/sizes:_A_1,_B_1-8 32.0B ± 0% 32.0B ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_5,_B_5-8 520B ± 0% 520B ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_5,_B_20-8 1.38kB ± 0% 1.38kB ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_1,_B_1000-8 49.2kB ± 0% 49.2kB ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_2,_B_1000-8 49.3kB ± 0% 49.3kB ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_1,_B_1-8 24.0B ± 0% 24.0B ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_5,_B_5-8 488B ± 0% 488B ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_5,_B_20-8 1.35kB ± 0% 1.35kB ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_1,_B_1000-8 49.2kB ± 0% 49.2kB ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_2,_B_1000-8 49.2kB ± 0% 49.2kB ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_1000,_B_2-8 49.2kB ± 0% 49.2kB ± 0% ~ (all equal) ParseCoin-8 2.21kB ± 0% 2.21kB ± 0% ~ (all equal) UintMarshal-8 392B ± 0% 392B ± 0% ~ (all equal) IntMarshal-8 168B ± 0% 168B ± 0% ~ (all equal) MarshalTo-8 80.0B ± 0% 80.0B ± 0% ~ (all equal) name old allocs/op new allocs/op delta CoinsAdditionIntersect/sizes:_A_1,_B_1-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_5,_B_5-8 12.0 ± 0% 12.0 ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_5,_B_20-8 14.0 ± 0% 14.0 ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_1,_B_1000-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) CoinsAdditionIntersect/sizes:_A_2,_B_1000-8 6.00 ± 0% 6.00 ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_1,_B_1-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_5,_B_5-8 5.00 ± 0% 5.00 ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_5,_B_20-8 6.00 ± 0% 6.00 ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_1,_B_1000-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_2,_B_1000-8 4.00 ± 0% 4.00 ± 0% ~ (all equal) CoinsAdditionNoIntersect/sizes:_A_1000,_B_2-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) ParseCoin-8 71.0 ± 0% 71.0 ± 0% ~ (all equal) UintMarshal-8 25.0 ± 0% 25.0 ± 0% ~ (all equal) IntMarshal-8 18.0 ± 0% 18.0 ± 0% ~ (all equal) MarshalTo-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) name old speed new speed delta UintMarshal-8 6.91MB/s ± 0% 6.99MB/s ± 0% +1.04% (p=0.008 n=5+5) IntMarshal-8 9.16MB/s ± 0% 9.23MB/s ± 1% +0.83% (p=0.032 n=5+5) Benchmark for github.com/cosmos/cosmos-sdk/x/mint/types: name old time/op new time/op delta BlockProvision-8 263ns ± 0% 257ns ± 0% -2.23% (p=0.008 n=5+5) name old alloc/op new alloc/op delta BlockProvision-8 112B ± 0% 104B ± 0% -7.14% (p=0.008 n=5+5) name old allocs/op new allocs/op delta BlockProvision-8 6.00 ± 0% 5.00 ± 0% -16.67% (p=0.008 n=5+5) Fixes #9249 Co-authored-by: Emmanuel T Odeke <[email protected]>
- Loading branch information