bitshares-core icon indicating copy to clipboard operation
bitshares-core copied to clipboard

Improve update_last_irreversible_block() performance

Open abitmore opened this issue 6 years ago • 3 comments

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

abitmore avatar Jul 01 '18 22:07 abitmore

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.

abitmore avatar Jan 15 '19 21:01 abitmore

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.

pmconrad avatar Jan 16 '19 13:01 pmconrad

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.)

abitmore avatar Feb 27 '21 15:02 abitmore