bitshares / bitshares/bitshares-core

Improve adjust_balance performance

Open
#1,083 11 comments 0 reactions 1 assignee Claimed by @abitmore View on GitHub
1b User Story 2a Discussion Needed 3c Enhancement 4b Normal Priority 6 API 6 Performance 9c Large performance
Dominant language
C++
Stars
1.2k
Forks
660
Avg merge
8h 17m
Merged PRs (30d)
26

Description

Replay profiling data:

```
Flat profile:

Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
22.90 574.86 574.86 948058596 0.00 0.00 graphene::chain::generic_index::find(graphene::db::object_id_type) const
10.99 850.85 275.99 391901309 0.00 0.00 graphene::chain::generic_index::modify(graphene::db::object const&, std::function const&)
6.41 1011.89 161.04 20731743387 0.00 0.00 graphene::chain::operator>(graphene::chain::price const&, graphene::chain::price const&)
4.31 1119.98 108.09 390785433 0.00 0.00 graphene::chain::database::adjust_balance(graphene::db::object_id<(unsigned char)1, (unsigned char)2, graphene::chain::account_object>, graphene::chain::asset)
4.18 1224.80 104.82 22671 0.00 0.01 graphene::chain::database::perform_chain_maintenance(graphene::chain::signed_block const&, graphene::chain::global_property_object const&)
3.56 1314.29 89.50 22967573183 0.00 0.00 graphene::chain::operator<(graphene::chain::price const&, graphene::chain::price const&)
3.40 1399.71 85.42 307443552 0.00 0.00 graphene::chain::generic_index::find(graphene::db::object_id_type) const
```

Note:
* the first entry (`account_index::find(object_id_type)`) will be discussed in #803. It's not in scope of this issue.
* The 2nd and 4th entries are related to `adjust_balance`.

Background: in order to implement `top_n_authorities` asset committee mechanism (for STEALTH), we added `by_asset_balance` into indices of `account_balance_index`, which impacted overall performance:
* most assets don't need `by_asset_balance` for consensus;
* even for assets enabled `top_n_authorities` (e.g. STEALTH), since the asset committee only gets updated in maintenance interval, it's an overkill to maintain `by_asset_balance` for consensus.

Another use of `by_asset_balance` is `asset_api::get_asset_holders`, which can be used to fetch holders of specified asset in descending order. Since it is not related to consensus, in addition, `asset_api` is not enabled by default due to potential performance issues (https://github.com/bitshares/bitshares-core/pull/312#issuecomment-308869443), I propose we move `by_asset_balance` to a plugin and refactor `asset_api`.

This is a sub-task of #982.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.