cosmos-sdk/types
Emmanuel T Odeke c2d5b24f58
store/cachekv: use typed types/kv.List instead of container/list.List (#8811)
Reduces CPU burn by using a typed List to avoid the expensive type
assertions from using an interface. This is the only option for now
until Go makes generics generally available.

The change brings time spent on the time assertion cummulatively to:
    580ms down from 6.88s

Explanation:
The type assertions were showing up heavily in profiles:
* Before this commit
```shell
Total: 42.18s
ROUTINE ======================== github.com/cosmos/cosmos-sdk/store/cachekv.newMemIterator
in /Users/emmanuelodeke/go/src/github.com/cosmos/cosmos-sdk/store/cachekv/memiterator.go
    14.01s     18.87s (flat, cum) 44.74% of Total
         .          .     17:	items      []*kv.Pair
         .          .     18:	ascending  bool
         .          .     19:}
         .          .     20:
         .          .     21:func newMemIterator(start, end []byte, items *list.List, ascending bool) *memIterator {
         .      620ms     22:	itemsInDomain := make([]*kv.Pair, 0, items.Len())
         .          .     23:
         .          .     24:	var entered bool
         .          .     25:
     510ms      870ms     26:	for e := items.Front(); e != nil; e = e.Next() {
     6.85s      6.88s     27:		item := e.Value.(*kv.Pair)
     5.71s      8.19s     28:		if !dbm.IsKeyInDomain(item.Key, start, end) {
     120ms      120ms     29:			if entered {
         .          .     30:				break
         .          .     31:			}
         .          .     32:
         .          .     33:			continue
         .          .     34:		}
         .          .     35:
     820ms      980ms     36:		itemsInDomain = append(itemsInDomain, item)
         .          .     37:		entered = true
         .          .     38:	}
         .          .     39:
         .      1.21s     40:	return &memIterator{
         .          .     41:		start:     start,
         .          .     42:		end:       end,
         .          .     43:		items:     itemsInDomain,
         .          .     44:		ascending: ascending,
         .          .     45:	}
```

and given that the list only uses that type, it is only right to lift the
code from container/list.List, and only modify Element.Value's type.

For emphasis, the code is basically just a retrofit of
container/list/list.go but with a typing, and we'll keep it as is
until perhaps Go1.17 or Go1.18 or when everyone uses Go1.17+ after
generics have landed.

* After this commit
```shell
Total: 45.25s
ROUTINE ======================== github.com/cosmos/cosmos-sdk/store/cachekv.newMemIterator
in /Users/emmanuelodeke/go/src/github.com/cosmos/cosmos-sdk/store/cachekv/memiterator.go
     4.84s      6.77s (flat, cum) 14.96% of Total
         .          .     16:	items      []*kv.Pair
         .          .     17:	ascending  bool
         .          .     18:}
         .          .     19:
         .          .     20:func newMemIterator(start, end []byte, items *kv.List, ascending bool) *memIterator {
         .      330ms     21:	itemsInDomain := make([]*kv.Pair, 0, items.Len())
         .          .     22:
         .          .     23:	var entered bool
         .          .     24:
      60ms      160ms     25:	for e := items.Front(); e != nil; e = e.Next() {
     580ms      580ms     26:		item := e.Value
     3.68s      4.78s     27:		if !dbm.IsKeyInDomain(item.Key, start, end) {
      80ms       80ms     28:			if entered {
         .          .     29:				break
         .          .     30:			}
         .          .     31:
         .          .     32:			continue
         .          .     33:		}
         .          .     34:
     440ms      580ms     35:		itemsInDomain = append(itemsInDomain, item)
         .          .     36:		entered = true
         .          .     37:	}
         .          .     38:
         .      260ms     39:	return &memIterator{
         .          .     40:		start:     start,
         .          .     41:		end:       end,
         .          .     42:		items:     itemsInDomain,
         .          .     43:		ascending: ascending,
         .          .     44:	}
```

Fixes #8810
2021-03-08 09:16:23 -08:00
..
address internal: create package for unsafe bytes convertion (#8733) 2021-03-01 15:10:22 +00:00
bech32 support multisig bech32 address decoding (#6237) 2020-07-23 16:53:47 +00:00
errors various linter fixes (#8666) 2021-02-23 08:46:01 +00:00
grpc Add GRPCBlockHeightHeader in clientCtx gRPC requests (#7021) 2020-08-12 14:42:10 +00:00
kv store/cachekv: use typed types/kv.List instead of container/list.List (#8811) 2021-03-08 09:16:23 -08:00
module x{stake,slash,gov,distrib} In-place Store Migrations (#8504) 2021-02-25 10:43:31 +00:00
msgservice implement x/authz module (#7629) 2021-01-25 16:41:30 +00:00
query [Bank] Remove the unsafe balance changing API (#8473) 2021-02-17 18:20:33 +00:00
rest cli: convert coins to smallest unit registered (#7777) 2020-11-16 11:34:54 +00:00
simulation various linter fixes (#8666) 2021-02-23 08:46:01 +00:00
tx gRPC gateway issue with colons in the account url path (#8649) 2021-02-22 11:30:45 +00:00
abci.go Merge PR #4613: Only change rootmultistore hash when substore hashes change 2019-06-25 13:11:22 -04:00
abci.pb.go Update gogo proto deps with v1.3.2 security fixes (#8350) 2021-01-15 19:45:34 +00:00
address.go Lock mutex on getting element from cache (#8767) 2021-03-03 15:52:38 +00:00
address_bench_test.go simapp, types: fix benchmarks panics by honoring skip if set (#8763) 2021-03-03 03:54:14 -08:00
address_test.go Refactor store keys for variable-length addresses (#8363) 2021-02-01 13:17:44 +00:00
bench_test.go run make format (#8642) 2021-02-19 15:02:53 +00:00
codec.go Add ADR 031 BaseApp and codec infrastructure (#7519) 2020-10-15 13:07:59 +00:00
coin.go cli: ParseCoin doesn't do normalize (#7954) 2020-11-25 18:02:10 +00:00
coin.pb.go Update gogo proto deps with v1.3.2 security fixes (#8350) 2021-01-15 19:45:34 +00:00
coin_benchmark_test.go all: ensure b.ReportAllocs() in all the benchmarks (#8460) 2021-01-27 23:52:08 -08:00
coin_test.go types/Coin: compile and reuse Regexps to reduce massive RAM+CPU burn (#7989) 2020-11-20 19:37:45 +00:00
config.go Deprecate SetFullFundraiserPath in favor of SetPurpose and SetCoinType (#8629) 2021-02-22 15:14:09 +00:00
config_test.go Deprecate SetFullFundraiserPath in favor of SetPurpose and SetCoinType (#8629) 2021-02-22 15:14:09 +00:00
context.go tendermint: update to rc3 (#6892) 2020-08-14 13:58:53 -04:00
context_test.go Add in-place store migrations (#8485) 2021-02-10 17:49:31 +00:00
dec_coin.go types/Coin: compile and reuse Regexps to reduce massive RAM+CPU burn (#7989) 2020-11-20 19:37:45 +00:00
dec_coin_test.go cli: convert coins to smallest unit registered (#7777) 2020-11-16 11:34:54 +00:00
decimal.go various linter fixes (#8666) 2021-02-23 08:46:01 +00:00
decimal_internal_test.go types: tests -> test suites migration (#7400) 2020-09-28 12:46:49 +02:00
decimal_test.go various linter fixes (#8666) 2021-02-23 08:46:01 +00:00
denom.go cli: convert coins to smallest unit registered (#7777) 2020-11-16 11:34:54 +00:00
denom_internal_test.go cli: convert coins to smallest unit registered (#7777) 2020-11-16 11:34:54 +00:00
events.go Rename GRPCRouter (#8079) 2020-12-04 15:06:50 +00:00
events_test.go init: Implement ADR 032 typed events (#7564) 2020-10-28 11:02:39 +00:00
handler.go fix types.ChainAnteDecorators() panic (#5742) 2020-03-03 16:57:33 +00:00
handler_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
int.go types: use (*math/big.Int).BitLen() == 0 to check if value is 0 (#8580) 2021-02-15 10:53:10 +00:00
int_internal_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
int_test.go types: use (*math/big.Int).BitLen() == 0 to check if value is 0 (#8580) 2021-02-15 10:53:10 +00:00
invariant.go Merge PR #4832: print all failed invariants only 2019-08-05 14:21:44 -04:00
invariant_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
proto.go linter: enable nolintlint (#6162) 2020-05-08 08:46:12 +00:00
queryable.go Merge PR #5421: Refactor Error Handling 2019-12-27 12:57:54 -05:00
result.go Refactor x/bank according to ADR 031 (#7520) 2020-10-13 09:05:46 +00:00
result_test.go Refactor x/bank according to ADR 031 (#7520) 2020-10-13 09:05:46 +00:00
router.go Remove duplicated Module.Route calls (#7716) 2020-10-29 22:01:09 +00:00
router_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
service_msg.go Use service Msgs in CLI tx commands (#8512) 2021-02-18 18:00:19 +00:00
staking.go Use enum instead of int32 for BondStatus (#7499) 2020-10-12 13:56:02 +00:00
staking_test.go Use enum instead of int32 for BondStatus (#7499) 2020-10-12 13:56:02 +00:00
store.go init commit (#7360) 2020-09-22 19:46:48 -04:00
store_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
tx_msg.go Rename GRPCRouter (#8079) 2020-12-04 15:06:50 +00:00
tx_msg_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
uint.go various linter fixes (#8666) 2021-02-23 08:46:01 +00:00
uint_internal_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00
uint_test.go types: use (*math/big.Int).BitLen() == 0 to check if value is 0 (#8580) 2021-02-15 10:53:10 +00:00
utils.go tendermint: update to rc3 (#6892) 2020-08-14 13:58:53 -04:00
utils_test.go types: tests -> test suites migration (#7405) 2020-09-29 13:29:10 +02:00