Go to file
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
.github build(deps): bump JamesIves/github-pages-deploy-action from 4.0.0 to 4.1.0 (#8792) 2021-03-05 08:43:33 +00:00
baseapp Make gRPC requests go through tendermint Query (#8549) 2021-02-15 10:01:44 +00:00
client Rename InfoImporter -> LegacyInfoImporter (#8739) 2021-03-01 20:09:01 +00:00
codec crypto: add secp256r1 (#8559) 2021-03-04 12:29:48 +00:00
contrib Refactor store keys for variable-length addresses (#8363) 2021-02-01 13:17:44 +00:00
cosmovisor cosmovisor: ln -s docs/run-node/cosmovisor.md cosmovisor/README.md (#8526) 2021-02-05 15:17:52 +00:00
crypto Enable secp256r1 (#8786) 2021-03-04 21:31:42 +00:00
docs Supply by denom Migrations (#8780) 2021-03-05 14:11:19 +00:00
internal/conv internal: create package for unsafe bytes convertion (#8733) 2021-03-01 15:10:22 +00:00
proto/cosmos Supply by denom Migrations (#8780) 2021-03-05 14:11:19 +00:00
scripts scripts: indent multiline commands (#8706) 2021-02-25 20:57:41 +00:00
server Move QueryTx functions to x/auth/tx (#8734) 2021-03-01 15:57:28 +00:00
simapp Remove IBC from the SDK (#8735) 2021-03-04 13:11:34 +00:00
snapshots snapshots: document use of ioutil.TempDir() (#8508) 2021-02-04 09:54:01 +00:00
std Add ADR 031 BaseApp and codec infrastructure (#7519) 2020-10-15 13:07:59 +00:00
store store/cachekv: use typed types/kv.List instead of container/list.List (#8811) 2021-03-08 09:16:23 -08:00
telemetry Minor Code Cleanup - gRPC queries (#6862) 2020-07-28 12:53:35 +00:00
tests Add in-place store migrations (#8485) 2021-02-10 17:49:31 +00:00
testutil Enable secp256r1 (#8786) 2021-03-04 21:31:42 +00:00
third_party/proto gRPC-gateway routes as alternative to legacy tendermint REST endpoints (#7965) 2020-11-25 15:58:11 +00:00
types store/cachekv: use typed types/kv.List instead of container/list.List (#8811) 2021-03-08 09:16:23 -08:00
version version --long displays replaced build dependencies (#7941) 2020-11-16 10:00:34 +00:00
x x/gov: fix NormalizeProposalType() return values (#8808) 2021-03-08 14:38:24 +00:00
.build.sh fix library file path (#8301) 2021-01-12 10:08:42 +00:00
.clang-format Fix clang-format to specific version (#7350) 2020-10-27 10:04:34 +00:00
.codecov.yml CI: Fix codecov flag project config (#7994) 2020-11-20 09:13:25 -05:00
.dockerignore Add basic Dockerfile to build all binaries and export gaiad 2018-04-10 12:39:47 +02:00
.gitattributes Merge PR #6426: Migrate API Server 2020-06-15 13:39:09 -04:00
.gitignore All Makefile proto commands use Docker (#7931) 2020-11-13 16:36:58 +00:00
.golangci.yml linter: enable nolintlint (#6162) 2020-05-08 08:46:12 +00:00
.goreleaser.yml ci: automate release post tag push (#6230) 2020-05-25 20:02:08 +02:00
.mergify.yml Update mergify (#8784) 2021-03-05 12:45:18 +00:00
CHANGELOG.md reduce gas costs by 10x for transient store operations (#8790) 2021-03-05 16:25:19 +00:00
CODE_OF_CONDUCT.md Update CODE_OF_CONDUCT.md (#7381) 2020-09-28 11:28:30 +02:00
CONTRIBUTING.md Update CONTRIBUTING.md Point Release Procedure (#7999) 2020-12-11 01:50:07 +00:00
Dockerfile Makefile: simplify and clean-up (#7453) 2020-10-05 10:22:18 +02:00
LICENSE
Makefile fix make protoc error (#8799) 2021-03-05 15:23:01 +00:00
README.md Remove IBC from the SDK (#8735) 2021-03-04 13:11:34 +00:00
SECURITY.md update SECURITY.md (#6263) 2020-05-21 11:12:51 +02:00
STABLE_RELEASES.md Stable Releases: Definition and Process (#6394) 2020-07-14 10:28:53 +02:00
buf.yaml fix proto generation (#8361) 2021-01-18 12:41:34 -03:00
docker-compose.yml buildsystem: simplify Makefile and ci automation (#7189) 2020-08-31 15:39:05 +02:00
go.mod build(deps): bump github.com/prometheus/common from 0.17.0 to 0.18.0 (#8727) 2021-03-01 08:27:13 +00:00
go.sum build(deps): bump github.com/prometheus/common from 0.17.0 to 0.18.0 (#8727) 2021-03-01 08:27:13 +00:00

README.md

Cosmos SDK

banner

The Cosmos-SDK is a framework for building blockchain applications in Golang. It is being used to build Gaia, the first implementation of the Cosmos Hub.

WARNING: The SDK has mostly stabilized, but we are still making some breaking changes.

Note: Requires Go 1.15+

Quick Start

To learn how the SDK works from a high-level perspective, go to the SDK Intro.

If you want to get started quickly and learn how to build on top of the SDK, please follow the SDK Application Tutorial. You can also fork the tutorial's repository to get started building your own Cosmos SDK application.

For more, please go to the Cosmos SDK Docs.

Cosmos Hub Mainnet

The Cosmos Hub application, gaia, has moved to its own repository. Go there to join the Cosmos Hub mainnet and more.

Interblockchain Communication (IBC)

The IBC module for the SDK has moved to its own repository. Go there to build and integrate with the IBC module.

Starport

If you are starting a new app or a new module you can use Starport to help you get started and speed up development. If you have any questions or find a bug, feel free to open an issue in the repo.

Disambiguation

This Cosmos-SDK project is not related to the React-Cosmos project (yet). Many thanks to Evan Coury and Ovidiu (@skidding) for this Github organization name. As per our agreement, this disambiguation notice will stay here.