Commit Graph

8 Commits

Author SHA1 Message Date
Spoorthi 40d22c7ab3 refactoring balance.coin validation 2021-08-03 19:43:38 +02:00
Spoorthi ce1e65083e adding checks to ensure denoms are sorted 2021-08-02 10:16:23 +02:00
Cuong Manh Le 42a4e4b432
x/bank/types: speedy up by singly sort balances without having to re-iterate (#9260)
The speed is the same as old implementation, but the new one uses slightly
less memory and make the code easier to maintain.

name                    old time/op    new time/op    delta
SanitizeBalances500-8      933µs ± 1%     935µs ± 1%     ~     (p=0.400 n=9+10)
SanitizeBalances1000-8    1.91ms ± 0%    1.92ms ± 0%   +0.58%  (p=0.000 n=10+10)

name                    old alloc/op   new alloc/op   delta
SanitizeBalances500-8      588kB ± 0%     556kB ± 0%   -5.41%  (p=0.000 n=9+9)
SanitizeBalances1000-8    1.18MB ± 0%    1.12MB ± 0%   -5.37%  (p=0.000 n=9+9)

name                    old allocs/op  new allocs/op  delta
SanitizeBalances500-8      5.02k ± 0%     4.02k ± 0%  -19.94%  (p=0.000 n=10+10)
SanitizeBalances1000-8     10.0k ± 0%      8.0k ± 0%  -19.93%  (p=0.000 n=9+10)

Fixes #9259
2021-05-05 14:36:25 +00:00
Robert Zaremba be4a965599
codec: Rename codec and marshaler interfaces (#9226)
* codec: Rename codec and marshaler interfaces, ref: 8413

* codec: remove BinaryBare

* changelog update

* Update comments and documentation

* adding doc string comments

* Update CHANGELOG.md

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>

* Update codec/codec.go

Co-authored-by: Marko <marbar3778@yahoo.com>

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
2021-04-29 10:46:22 +00:00
Emmanuel T Odeke dbb9923917
store/cachekv, x/bank/types: algorithmically fix pathologically slow code (#8719)
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>
2021-02-27 07:26:22 -08:00
Marko a786830bb4
auth: allow 0 coin accounts in genesis (#8714)
* allow zero accounts

* fix test

* fix test
2021-02-26 15:41:48 +00:00
Alessio Treglia 8001e3ca3a
bank: don't ignore errors returned by Balance.GetAddress() (#8531)
Closes: #8530
2021-02-06 21:51:26 +00:00
Federico Kunze 7d4f7f93fe
x/bank: balance and metadata validation (#8417)
* x/bank: balance validation

* metadata validation

* minor change

* balance and metadata tests

* changelog

* check for empty coins

* genesis test
2021-01-22 21:44:54 -03:00