Try to improve update_last_irreversible_block performance#2045
Open
pmconrad wants to merge 2 commits intobitshares:developfrom
Open
Try to improve update_last_irreversible_block performance#2045pmconrad wants to merge 2 commits intobitshares:developfrom
pmconrad wants to merge 2 commits intobitshares:developfrom
Conversation
abitmore
reviewed
Feb 27, 2021
| const auto& witness_idx = get_index_type<witness_index>().indices().get<by_last_block>(); | ||
| auto itr = witness_idx.end(); | ||
| for( uint32_t i = gpo.active_witnesses.size() - offset; i > 0; --i ) | ||
| --itr; |
Member
There was a problem hiding this comment.
I think this is the main place where the performance got (slightly) lost, because we walk number_of_active_witnesses/2 steps on each new block. Each step costs log(number_of_all_witnesses).
My thoughts:
- maintain a small set containing the witnesses that produced a block after LIB and are still in the active witness list;
- maintain a pointer/iterator to the current witness that holds the LIB, and probably another pointer/iterator to its next witness in the set for better performance;
- when a new block comes,
- if its witness is already in the set, LIB does not change;
- otherwise, add the new witness into the set,
- if the new set size is smaller than or equal to
number_of_active_witnesses/2, LIB does not change; - otherwise, move the pointer/iterator and LIB to the next witness in the set, and remove the old one from the set.
- if the new set size is smaller than or equal to
With this approach we walk one, two or three steps on each new block within a smaller set with cost log(number_of_active_witnesses) (one for the lookup (if a witness is already in the set), one for adding it, another for removing the old). This can probably be done with a secondary index to keep data consistency. Not sure how much performance gain it will bring though.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Attempt to resolve #1105
Speed increase is insignificant (4 seconds for 22M blocks).
The first commit compares the new calculation method against the old, the second commit removes the old method.