Skip to content
New issue

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

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

Already on GitHub? # to your account

Address performance regression in vote_cache::top #4627

Merged
merged 3 commits into from
May 19, 2024

Conversation

clemahieu
Copy link
Contributor

Revert c734caf which removed loop short-circuit checking for top voted-for elections.
Eliminate duplicate expression evaluation.
Use deque rather than vector for results to reduce backing reallocation.

@clemahieu clemahieu requested a review from pwojcikdev May 17, 2024 13:24
Copy link
Contributor

@pwojcikdev pwojcikdev left a comment

Choose a reason for hiding this comment

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

I can't remember why I removed the by tally index, seems to make no sense.

EDIT:
Okay, so tally () is not a constant time function:

return std::accumulate (voters.begin (), voters.end (), nano::uint128_t{ 0 }, [] (auto sum, auto const & item) {
   return sum + item.weight;
});

Did you measure that the additional overhead on each insertion is worth the speedup during lookup? In any case, it's possible to implement some kind of smart tally caching to alleviate this issue and have both fast insertion and top lookup.

@qwahzi qwahzi added this to the V27 milestone May 18, 2024
@pwojcikdev pwojcikdev merged commit 5142047 into nanocurrency:develop May 19, 2024
22 of 26 checks passed
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants