bitshares-core
bitshares-core copied to clipboard
Improve update_last_irreversible_block() performance
For better performance, do this in maintenance interval rather than on every new block: https://github.com/bitshares/bitshares-core/blob/06aee789a4e2045d899e02b096d5a1a908be2865/libraries/chain/db_update.cpp#L129-L132
An idea is to add an index on last_confirmed_block_num
field to witness_index
, so the order will be automatically maintained. In addition, for better performance, carefully maintain a secondary index to keep track of the nth witness. I guess it would improve performance a bit. If we don't use a secondary index, we would have to travel from head to find the nth witness every time, which is not the best.
Good idea to index on last_confirmed_block_num
. This avoids copying and sorting stuff in every block, and the index only needs to update one witness at a time.
A secondary index will be a nightmare during maintenance, it's probably better to simply iterate through the original index. Can still improve on that later.
A new comment added here https://github.com/bitshares/bitshares-core/pull/2045/files#r584147551 about using a secondary index or simply iterating on each block. (Just found it's not a new idea.)