dbb9923917
After continuously profiling InitGensis with 100K accounts, it showed pathologically slow code, that was the result of a couple of patterns: * Unconditional and not always necessary map lookups * O(n^2) sdk.AccAddressFromBech32 retrievals when the code is expensive, during a quicksort The remedy involved 4 parts: * O(n) sdk.AccAddressFromBech32 invocations, down from O(n^2) in the quicksort * Only doing map lookups when the domain key check has passed * Using a black magic compiler technique of the map clearing idiom * Zero allocation []byte<->string conversion With 100K accounts, this brings InitGenesis down to ~6min, instead of 20+min, it reduces the sort code from ~7sec down to 50ms. Also some simple benchmark reflect the change: ```shell name old time/op new time/op delta SanitizeBalances500-8 19.3ms ±10% 1.5ms ± 5% -92.46% (p=0.000 n=20+20) SanitizeBalances1000-8 41.9ms ± 8% 3.0ms ±12% -92.92% (p=0.000 n=20+20) name old alloc/op new alloc/op delta SanitizeBalances500-8 9.05MB ± 6% 0.56MB ± 0% -93.76% (p=0.000 n=20+18) SanitizeBalances1000-8 20.2MB ± 3% 1.1MB ± 0% -94.37% (p=0.000 n=20+19) name old allocs/op new allocs/op delta SanitizeBalances500-8 72.4k ± 6% 4.5k ± 0% -93.76% (p=0.000 n=20+20) SanitizeBalances1000-8 162k ± 3% 9k ± 0% -94.40% (p=0.000 n=20+20) ``` The CPU profiles show the radical change as per https://github.com/cosmos/cosmos-sdk/issues/7766#issuecomment-786671734 Later on, we shall do more profiling and fixes but for now this brings down the run-time for InitGenesis. Fixes #7766 Co-authored-by: Alessio Treglia <alessio@tendermint.com> |
||
---|---|---|
.. | ||
auth | ||
authz | ||
bank | ||
capability | ||
crisis | ||
distribution | ||
evidence | ||
feegrant | ||
genaccounts | ||
genutil | ||
gov | ||
ibc | ||
mint | ||
params | ||
simulation | ||
slashing | ||
staking | ||
upgrade | ||
README.md |
README.md
List of Modules
Here are some production-grade modules that can be used in Cosmos SDK applications, along with their respective documentation:
- Auth - Authentication of accounts and transactions for Cosmos SDK application.
- Authz - Authorization for accounts to perform actions on behalf of other accounts.
- Bank - Token transfer functionalities.
- Capability - Object capability implementation.
- Crisis - Halting the blockchain under certain circumstances (e.g. if an invariant is broken).
- Distribution - Fee distribution, and staking token provision distribution.
- Evidence - Evidence handling for double signing, misbehaviour, etc.
- Governance - On-chain proposals and voting.
- IBC - IBC protocol for transport, authentication and ordering.
- IBC Transfer - Cross-chain fungible token transfer implementation through IBC.
- Mint - Creation of new units of staking token.
- Params - Globally available parameter store.
- Slashing - Validator punishment mechanisms.
- Staking - Proof-of-Stake layer for public blockchains.
- Upgrade - Software upgrades handling and coordination.
To learn more about the process of building modules, visit the building modules reference documentation.