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

Improve validator exit flow #2695

Merged
merged 4 commits into from
Jun 16, 2021
Merged

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Jun 14, 2021

Motivation

  • Processing a block with 16 validator exits is 100x times slower than regular block
  • Slashing validator triggers validator exit also

Description

  • Most of the time was for looping through validators, create a cache (ValidatorExitProcess) per block to make sure we loop through it at most 1 time
  • Minimize for loop inside initiateValidatorExit
  • The result in block.perf.ts is reduced from 100x to 6x, notice that processing 1 validator exit takes almost the same time to processing 16 validator exits
// Process block
// ================================================================
// Process block with 0 validator exit                                    233.6434 ops/s      4.280027 ms/op   3491 runs    15.01 s
// Process block with 1 validator exit                                    41.33581 ops/s      24.19210 ms/op    619 runs    15.00 s
// Process block with 16 validator exits                                  42.34492 ops/s      23.61558 ms/op    635 runs    15.02 s

Closes #2342

@codeclimate
Copy link

codeclimate bot commented Jun 14, 2021

Code Climate has analyzed commit 842e889 and detected 8 issues on this pull request.

Here's the issue category breakdown:

Category Count
Complexity 2
Duplication 6

View more on Code Climate.

@twoeths twoeths marked this pull request as ready for review June 14, 2021 02:00
Copy link
Contributor

@dapplion dapplion left a comment

Choose a reason for hiding this comment

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

Awesome performance boost! Tho I think it would be simpler to refactor the ValidatorExitProcess into a BlockProcess and make it mandatory param in the function signature.

@twoeths twoeths marked this pull request as draft June 16, 2021 08:48
@twoeths twoeths force-pushed the tuyen/improve-validator-exit branch from f354c59 to 40b767a Compare June 16, 2021 08:50
@twoeths twoeths marked this pull request as ready for review June 16, 2021 09:30
Copy link
Contributor

@dapplion dapplion left a comment

Choose a reason for hiding this comment

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

Looks great! Nice perf boost 🚀 We should add a benchmark for attester slashing and proposer slashing too

@wemeetagain wemeetagain merged commit 9a42a1c into master Jun 16, 2021
@wemeetagain wemeetagain deleted the tuyen/improve-validator-exit branch June 16, 2021 16:40
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.

Potential performance issue in initiateValidatorExit()
3 participants