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

Forkchoice optimize hex to bytes conversions #3118

Merged
merged 2 commits into from
Sep 14, 2021

Conversation

dapplion
Copy link
Contributor

@dapplion dapplion commented Sep 12, 2021

Motivation

Improve fork-choice performance in low hanging fruit areas

Description

  • Do a minimum conversions from Root to RootHex. ForkChoice, StateCache and API want strings - DB wants bytes. A lot of code is updated to only convert when necessary.
  • Don't iterate over the entire forkchoice nodes unless it's necessary. Fns iterateAncestors was not an iterator, so it would buffer all nodes first, then iterate. PRs adds like in SSZ iterate and getAll variants Optimize fork-choice iterators #3125
  • On re-orgs the code to compute the ancestor distance iterated over all nodes multiple times. Now it's more efficient walking the minimum nodes necessary Optimize fork-choice iterators #3125
  • Move ForkChoiceStore to fork-choice package. Allows to use a custom CheckpointWithHex type to achieve point 1. Re-org Lodestar ForkChoice instantiation #3122

@codeclimate
Copy link

codeclimate bot commented Sep 12, 2021

Code Climate has analyzed commit cb1ae5f and detected 0 issues on this pull request.

View more on Code Climate.

@github-actions
Copy link
Contributor

github-actions bot commented Sep 12, 2021

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 7bf2935 Previous: c88e4ec Ratio
BeaconState.hashTreeRoot - No change 1.0410 us/op 697.00 ns/op 1.49
BeaconState.hashTreeRoot - 1 full validator 102.88 us/op 81.578 us/op 1.26
BeaconState.hashTreeRoot - 32 full validator 1.4366 ms/op 1.1245 ms/op 1.28
BeaconState.hashTreeRoot - 512 full validator 20.385 ms/op 14.363 ms/op 1.42
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 105.44 us/op 80.186 us/op 1.32
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.3434 ms/op 1.1623 ms/op 1.16
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 24.425 ms/op 16.415 ms/op 1.49
BeaconState.hashTreeRoot - 1 balances 76.170 us/op 58.537 us/op 1.30
BeaconState.hashTreeRoot - 32 balances 599.60 us/op 501.27 us/op 1.20
BeaconState.hashTreeRoot - 512 balances 6.3349 ms/op 4.6590 ms/op 1.36
BeaconState.hashTreeRoot - 250000 balances 124.33 ms/op 88.961 ms/op 1.40
processSlot - 1 slots 53.674 us/op 49.460 us/op 1.09
processSlot - 32 slots 2.8884 ms/op 2.4170 ms/op 1.20
getCommitteeAssignments - req 1 vs - 250000 vc 6.5433 ms/op 4.3652 ms/op 1.50
getCommitteeAssignments - req 100 vs - 250000 vc 9.1143 ms/op 6.3666 ms/op 1.43
getCommitteeAssignments - req 1000 vs - 250000 vc 9.8467 ms/op 6.8244 ms/op 1.44
computeProposers - vc 250000 27.933 ms/op 20.534 ms/op 1.36
computeEpochShuffling - vc 250000 251.97 ms/op 176.57 ms/op 1.43
getNextSyncCommittee - vc 250000 464.52 ms/op 349.58 ms/op 1.33
altair processBlock - 250000 vs - 7PWei normalcase 137.46 ms/op 80.564 ms/op 1.71
altair processBlock - 250000 vs - 7PWei worstcase 302.30 ms/op 206.74 ms/op 1.46
altair processEpoch - pyrmont_e62330 674.47 ms/op 473.15 ms/op 1.43
pyrmont_e62330 - altair beforeProcessEpoch 205.01 ms/op 143.51 ms/op 1.43
pyrmont_e62330 - altair processJustificationAndFinalization 96.715 us/op 126.23 us/op 0.77
pyrmont_e62330 - altair processInactivityUpdates 89.765 ms/op 62.813 ms/op 1.43
pyrmont_e62330 - altair processRewardsAndPenalties 74.995 ms/op 50.101 ms/op 1.50
pyrmont_e62330 - altair processRegistryUpdates 15.464 us/op 24.342 us/op 0.64
pyrmont_e62330 - altair processSlashings 3.9100 us/op 6.8930 us/op 0.57
pyrmont_e62330 - altair processEth1DataReset 3.4280 us/op 5.6580 us/op 0.61
pyrmont_e62330 - altair processEffectiveBalanceUpdates 7.5049 ms/op 4.8949 ms/op 1.53
pyrmont_e62330 - altair processSlashingsReset 22.347 us/op 36.946 us/op 0.60
pyrmont_e62330 - altair processRandaoMixesReset 29.978 us/op 47.813 us/op 0.63
pyrmont_e62330 - altair processHistoricalRootsUpdate 4.4220 us/op 7.9820 us/op 0.55
pyrmont_e62330 - altair processParticipationFlagUpdates 61.665 ms/op 54.517 ms/op 1.13
pyrmont_e62330 - altair processSyncCommitteeUpdates 3.3450 us/op 4.4950 us/op 0.74
pyrmont_e62330 - altair afterProcessEpoch 146.97 ms/op 113.76 ms/op 1.29
altair processInactivityUpdates - 250000 normalcase 267.48 ms/op 196.51 ms/op 1.36
altair processInactivityUpdates - 250000 worstcase 258.88 ms/op 202.91 ms/op 1.28
altair processParticipationFlagUpdates - 250000 anycase 118.54 ms/op 93.559 ms/op 1.27
altair processRewardsAndPenalties - 250000 normalcase 157.97 ms/op 106.42 ms/op 1.48
altair processRewardsAndPenalties - 250000 worstcase 174.38 ms/op 105.55 ms/op 1.65
altair processSyncCommitteeUpdates - 250000 487.11 ms/op 356.84 ms/op 1.37
Tree 40 250000 create 780.46 ms/op 450.64 ms/op 1.73
Tree 40 250000 get(125000) 344.78 ns/op 231.11 ns/op 1.49
Tree 40 250000 set(125000) 2.2872 us/op 1.4435 us/op 1.58
Tree 40 250000 toArray() 56.332 ms/op 55.324 ms/op 1.02
Tree 40 250000 iterate all - toArray() + loop 56.767 ms/op 49.764 ms/op 1.14
Tree 40 250000 iterate all - get(i) 145.23 ms/op 94.976 ms/op 1.53
MutableVector 250000 create 31.249 ms/op 18.624 ms/op 1.68
MutableVector 250000 get(125000) 16.195 ns/op 11.906 ns/op 1.36
MutableVector 250000 set(125000) 948.82 ns/op 435.17 ns/op 2.18
MutableVector 250000 toArray() 11.233 ms/op 6.1626 ms/op 1.82
MutableVector 250000 iterate all - toArray() + loop 11.562 ms/op 7.3625 ms/op 1.57
MutableVector 250000 iterate all - get(i) 4.0210 ms/op 3.2723 ms/op 1.23
Array 250000 create 8.6427 ms/op 4.5865 ms/op 1.88
Array 250000 clone - spread 4.4028 ms/op 1.5987 ms/op 2.75
Array 250000 get(125000) 1.5300 ns/op 0.82400 ns/op 1.86
Array 250000 set(125000) 1.5270 ns/op 0.74700 ns/op 2.04
Array 250000 iterate all - loop 210.24 us/op 117.70 us/op 1.79
aggregationBits - 2048 els - readonlyValues 405.36 us/op 203.30 us/op 1.99
aggregationBits - 2048 els - zipIndexesInBitList 81.582 us/op 34.619 us/op 2.36
ssz.Root.equals 2.1130 us/op 1.1450 us/op 1.85
ssz.Root.equals with valueOf() 2.6570 us/op 1.2770 us/op 2.08
byteArrayEquals with valueOf() 2.5660 us/op 1.2880 us/op 1.99
phase0 processBlock - 250000 vs - 7PWei normalcase 16.551 ms/op 12.071 ms/op 1.37
phase0 processBlock - 250000 vs - 7PWei worstcase 102.59 ms/op 80.490 ms/op 1.27
phase0 afterProcessEpoch - 250000 vs - 7PWei 269.31 ms/op 181.00 ms/op 1.49
phase0 beforeProcessEpoch - 250000 vs - 7PWei 824.02 ms/op 639.21 ms/op 1.29
phase0 processEpoch - mainnet_e58758 1.1233 s/op 830.86 ms/op 1.35
mainnet_e58758 - phase0 beforeProcessEpoch 657.64 ms/op 535.48 ms/op 1.23
mainnet_e58758 - phase0 processJustificationAndFinalization 118.46 us/op 119.89 us/op 0.99
mainnet_e58758 - phase0 processRewardsAndPenalties 109.31 ms/op 72.246 ms/op 1.51
mainnet_e58758 - phase0 processRegistryUpdates 60.321 us/op 106.02 us/op 0.57
mainnet_e58758 - phase0 processSlashings 4.0080 us/op 7.2660 us/op 0.55
mainnet_e58758 - phase0 processEth1DataReset 3.4560 us/op 5.5650 us/op 0.62
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 11.892 ms/op 8.4705 ms/op 1.40
mainnet_e58758 - phase0 processSlashingsReset 19.865 us/op 36.649 us/op 0.54
mainnet_e58758 - phase0 processRandaoMixesReset 26.229 us/op 48.786 us/op 0.54
mainnet_e58758 - phase0 processHistoricalRootsUpdate 4.2810 us/op 7.7380 us/op 0.55
mainnet_e58758 - phase0 processParticipationRecordUpdates 17.214 us/op 35.129 us/op 0.49
mainnet_e58758 - phase0 afterProcessEpoch 240.02 ms/op 165.27 ms/op 1.45
phase0 processEffectiveBalanceUpdates - 250000 normalcase 14.778 ms/op 10.008 ms/op 1.48
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.8872 s/op 1.5272 s/op 1.24
phase0 processRegistryUpdates - 250000 normalcase 70.065 us/op 104.50 us/op 0.67
phase0 processRegistryUpdates - 250000 badcase_full_deposits 4.3260 ms/op 4.1071 ms/op 1.05
phase0 processRegistryUpdates - 250000 worstcase 0.5 2.3818 s/op 1.9752 s/op 1.21
phase0 getAttestationDeltas - 250000 normalcase 44.093 ms/op 33.892 ms/op 1.30
phase0 getAttestationDeltas - 250000 worstcase 44.688 ms/op 35.510 ms/op 1.26
phase0 processSlashings - 250000 worstcase 52.975 ms/op 36.715 ms/op 1.44
shuffle list - 16384 els 17.089 ms/op 12.649 ms/op 1.35
shuffle list - 250000 els 235.40 ms/op 175.32 ms/op 1.34
getEffectiveBalances - 250000 vs - 7PWei 17.117 ms/op 9.5631 ms/op 1.79
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 3.2498 ms/op 2.0718 ms/op 1.57
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 1.3525 ms/op 862.66 us/op 1.57
BLS verify - blst-native 2.3352 ms/op 1.9029 ms/op 1.23
BLS verifyMultipleSignatures 3 - blst-native 4.7832 ms/op 3.6535 ms/op 1.31
BLS verifyMultipleSignatures 8 - blst-native 10.312 ms/op 8.0102 ms/op 1.29
BLS verifyMultipleSignatures 32 - blst-native 37.426 ms/op 28.538 ms/op 1.31
BLS aggregatePubkeys 32 - blst-native 50.401 us/op 38.328 us/op 1.31
BLS aggregatePubkeys 128 - blst-native 195.25 us/op 153.68 us/op 1.27
getAttestationsForBlock 124.77 ms/op 73.490 ms/op 1.70
CheckpointStateCache - add get delete 20.596 us/op 15.739 us/op 1.31
validate gossip signedAggregateAndProof - struct 5.5947 ms/op 4.2747 ms/op 1.31
validate gossip signedAggregateAndProof - treeBacked 5.5765 ms/op 4.3697 ms/op 1.28
validate gossip attestation - struct 2.5899 ms/op 2.0315 ms/op 1.27
validate gossip attestation - treeBacked 2.6243 ms/op 2.1925 ms/op 1.20

by benchmarkbot/action

@dapplion dapplion force-pushed the dapplion/forkchoice-optimizations branch from bc5e240 to f5b35f6 Compare September 14, 2021 09:48
@dapplion dapplion changed the title Forkchoice optimizations Forkchoice optimize hex to bytes conversions Sep 14, 2021
@codecov
Copy link

codecov bot commented Sep 14, 2021

Codecov Report

Merging #3118 (cb1ae5f) into master (7beccf0) will decrease coverage by 0.35%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #3118      +/-   ##
==========================================
- Coverage   58.78%   58.42%   -0.36%     
==========================================
  Files         374      374              
  Lines        9091     9218     +127     
  Branches     1348     1380      +32     
==========================================
+ Hits         5344     5386      +42     
- Misses       3365     3450      +85     
  Partials      382      382              

Copy link
Member

@wemeetagain wemeetagain left a comment

Choose a reason for hiding this comment

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

💯

@wemeetagain wemeetagain merged commit c65dc37 into master Sep 14, 2021
@wemeetagain wemeetagain deleted the dapplion/forkchoice-optimizations branch September 14, 2021 20:34
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.

None yet

3 participants