Noticed while examining a bunch of profiles, that the for loop inside
(*CompactBitArry).NumTrueBitsBefore unnecessarily consumed a bunch of
time:
```shell
7.55s 9.88s (flat, cum) 93.38% of Total
240ms 250ms 88:func (bA *CompactBitArray) NumTrueBitsBefore(index int) int {
. . 89: onesCount := 0
70ms 340ms 90: max := bA.Count()
70ms 70ms 91: if index > max {
. . 92: index = max
. . 93: }
. . 94: // below we iterate over the bytes then over bits (in low endian) and count bits set to 1
2.54s 2.76s 95: for elem := 0; elem < len(bA.Elems); elem++ {
```
but we can use the native for loop that produces indices while iterating
over slices. Just by simply changing the form results in an improvement
```shell
7.50s 9.95s (flat, cum) 94.94% of Total
240ms 320ms 88:func (bA *CompactBitArray) NumTrueBitsBefore(index int) int {
. . 89: onesCount := 0
170ms 420ms 90: max := bA.Count()
90ms 100ms 91: if index > max {
. . 92: index = max
. . 93: }
. . 94: // below we iterate over the bytes then over bits (in low endian) and count bits set to 1
1.49s 1.62s 95: for elem := range bA.Elems {
```
and an improvement in CPU time
```shell
$ benchstat before.txt after.txt
name old time/op new time/op delta
NumTrueBitsBefore/new-8 13.3ns ± 1% 12.5ns ± 1% -6.07% (p=0.000 n=10+10)
name old alloc/op new alloc/op delta
NumTrueBitsBefore/new-8 0.00B 0.00B ~ (all equal)
name old allocs/op new allocs/op delta
NumTrueBitsBefore/new-8 0.00 0.00 ~ (all equal)
```
Fixes #13999
|
||
|---|---|---|
| .github | ||
| .vscode | ||
| api | ||
| baseapp | ||
| client | ||
| codec | ||
| contrib | ||
| core | ||
| crypto | ||
| depinject | ||
| docs | ||
| errors | ||
| fuzz | ||
| internal | ||
| math | ||
| orm | ||
| proto | ||
| runtime | ||
| scripts | ||
| server | ||
| simapp | ||
| snapshots | ||
| std | ||
| store | ||
| telemetry | ||
| tests | ||
| testutil | ||
| third_party/proto | ||
| tools | ||
| tx | ||
| types | ||
| version | ||
| x | ||
| .clang-format | ||
| .dockerignore | ||
| .gitattributes | ||
| .gitignore | ||
| .gitpod.yml | ||
| .golangci.yml | ||
| .goreleaser.yml | ||
| .markdownlint.json | ||
| .markdownlintignore | ||
| .mergify.yml | ||
| buf.work.yaml | ||
| CHANGELOG.md | ||
| CODE_OF_CONDUCT.md | ||
| CODING_GUIDELINES.md | ||
| CONTRIBUTING.md | ||
| docker-compose.yml | ||
| Dockerfile | ||
| go.mod | ||
| go.sum | ||
| go.work.example | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
| RELEASE_PROCESS.md | ||
| SECURITY.md | ||
| sonar-project.properties | ||
| UPGRADING.md | ||
Cosmos SDK
The Cosmos SDK is a framework for building blockchain applications. Tendermint Core (BFT Consensus) and the Cosmos SDK are written in the Go programming language. Cosmos SDK is used to build Gaia, the implementation of the Cosmos Hub.
WARNING: The Cosmos SDK has mostly stabilized, but we are still making some breaking changes.
Note: Requires Go 1.19+
Quick Start
To learn how the Cosmos SDK works from a high-level perspective, see the Cosmos SDK High-Level Intro.
If you want to get started quickly and learn how to build on top of Cosmos SDK, visit Cosmos SDK Tutorials. You can also fork the tutorial's repository to get started building your own Cosmos SDK application.
For more information, see the Cosmos SDK Documentation.
Contributing
See CONTRIBUTING.md for details on how to contribute and participate in our dev calls. If you want to follow the updates or learn more about the latest design then join our Discord.
Tools and Frameworks
The Cosmos ecosystem is vast. Awesome Cosmos is a community-curated list of notable frameworks, modules and tools.
Cosmos Hub Mainnet
The Cosmos Hub application, gaia, has its own cosmos/gaia repository. Go there to join the Cosmos Hub mainnet and more.
Inter-Blockchain Communication (IBC)
The IBC module for the Cosmos SDK has its own cosmos/ibc-go repository. Go there to build and integrate with the IBC module.
Ignite CLI
Ignite CLI is the all-in-one platform to build, launch, and maintain any crypto application on a sovereign and secured blockchain. If you are building a new app or a new module, use Ignite CLI to get started and speed up development.
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.
