Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to improve update_last_irreversible_block performance #2045

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

pmconrad
Copy link
Contributor

@pmconrad pmconrad commented Nov 5, 2019

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.

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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants