From 30f4b3f3d9cf3e04e53ca3d7b3423b7377ff0cc7 Mon Sep 17 00:00:00 2001 From: DongLieu Date: Tue, 26 Dec 2023 16:13:18 +0700 Subject: [PATCH 1/3] perf: Speedup DecCoin.Sort() when coins is of length 1 --- types/dec_coin.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/types/dec_coin.go b/types/dec_coin.go index b844301f8c84..c1bbcc6a8ecf 100644 --- a/types/dec_coin.go +++ b/types/dec_coin.go @@ -615,7 +615,12 @@ func (coins DecCoins) Swap(i, j int) { coins[i], coins[j] = coins[j], coins[i] } // Sort is a helper function to sort the set of decimal coins in-place. func (coins DecCoins) Sort() DecCoins { - sort.Sort(coins) + // sort.Sort(coins) does a costly runtime copy as part of `runtime.convTSlice` + // So we avoid this heap allocation if len(coins) <= 1. In the future, we should hopefully find + // a strategy to always avoid this. + if len(coins) > 1 { + sort.Sort(coins) + } return coins } From b7f60d885fe74da60076af7003657cddbe4f68fa Mon Sep 17 00:00:00 2001 From: DongLieu Date: Tue, 26 Dec 2023 16:24:45 +0700 Subject: [PATCH 2/3] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eccc2b708a80..634064bb453d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +* (types) [#18875](https://github.com/cosmos/cosmos-sdk/pull/18888) Speedup DecCoin.Sort() if len(coins) <= 1 * (types) [#18875](https://github.com/cosmos/cosmos-sdk/pull/18875) Speedup coins.Sort() if len(coins) <= 1 * (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. * (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve ` keys add -i` by hiding inputting of bip39 passphrase. From 297fb336291d2787546467134951b7783e43e597 Mon Sep 17 00:00:00 2001 From: DongLieu Date: Tue, 26 Dec 2023 16:28:19 +0700 Subject: [PATCH 3/3] minor --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 634064bb453d..925a03e88b9c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,7 +54,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements -* (types) [#18875](https://github.com/cosmos/cosmos-sdk/pull/18888) Speedup DecCoin.Sort() if len(coins) <= 1 +* (types) [#18888](https://github.com/cosmos/cosmos-sdk/pull/18888) Speedup DecCoin.Sort() if len(coins) <= 1 * (types) [#18875](https://github.com/cosmos/cosmos-sdk/pull/18875) Speedup coins.Sort() if len(coins) <= 1 * (client/keys) [#18745](https://github.com/cosmos/cosmos-sdk/pull/18745) Improve ` keys export` and ` keys mnemonic` by adding --yes option to skip interactive confirmation. * (client/keys) [#18743](https://github.com/cosmos/cosmos-sdk/pull/18743) Improve ` keys add -i` by hiding inputting of bip39 passphrase.