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

feat: implement BalancesTreeCache #7084

Merged
merged 2 commits into from
Sep 14, 2024

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Sep 14, 2024

Motivation

  • At every epoch transition, we always create balances tree from scratch and it causes memory spikes at processRewardsAndPenalties step (10m) chart:
Screenshot 2024-09-14 at 14 33 10

Description

Resolves #6229

Testing

  • processRewardsAndPenalties 10m is improved a lot, there are 2 spikes in 12h time frame, most likely due to batchHashTreeRoot() we used inside ListUintNum64Type.toViewDU(value, viewDU)
Screenshot 2024-09-14 at 14 42 13
  • 6h chart shows ~250ms save in average
Screenshot 2024-09-14 at 14 44 29
  • but prepareNextEpoch is saved ~350ms because we hashed state.balances in ListUintNum64Type.toViewDU(value, viewDU), and that's majority of hash work for prepareNextEpoch
Screenshot 2024-09-14 at 14 47 28
  • state.hashTreeRoot() is not a little bit confusing, but majority of work is done by this work and state.validators.commit()
Screenshot 2024-09-14 at 14 49 01

@twoeths
Copy link
Contributor Author

twoeths commented Sep 14, 2024

a note about BalancesTreeCache, if network is not finalized in an epoch then we'll miss the cache

Screenshot 2024-09-14 at 15 16 09

it's not likely to miss the cache if we go with n-historical flag

with an average time of ~830s afterProcessEpoch

Screenshot 2024-09-14 at 15 17 10

we can expect the prepareNextEpoch on holesky to be around 1.35s - 0.8s ~= 550ms

@twoeths twoeths marked this pull request as ready for review September 14, 2024 08:18
@twoeths twoeths requested a review from a team as a code owner September 14, 2024 08:18
@twoeths twoeths merged commit 604a2a7 into te/batch_hash_tree_root Sep 14, 2024
13 of 17 checks passed
@twoeths twoeths deleted the te/reuse_balances_tree branch September 14, 2024 08:18
@twoeths
Copy link
Contributor Author

twoeths commented Oct 1, 2024

works well for a while (more than 2w of testing)

Screenshot 2024-10-01 at 15 55 22

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.

1 participant