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: load state from Uint8Array #6057

Merged
merged 12 commits into from
Oct 31, 2023
Merged

feat: load state from Uint8Array #6057

merged 12 commits into from
Oct 31, 2023

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Oct 22, 2023

Motivation

  • Add capability to load state from Uint8Array to a beacon node which use the same base tree, this gives us some benefit:
    • single base tree across the application
    • faster to load state
    • less memory usage

Description

  • This started from feat: n historical states #6008
  • Implement loadValidators() api which use the same validators tree of seed state and return modified validators. This comes from the fact that validators are rarely changed
  • Also inactivityScores are rarely changed as monitored on mainnet
  • Implement loadCachedBeaconState() api which call loadState() and update modified validators to the pubkey cache
  • Use ssz 0.14.0
  • No consumer of "loadState()" api for now

part of #5968

TODO: coordinate with #6042

@github-actions
Copy link
Contributor

github-actions bot commented Oct 23, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 925176f Previous: cf13ce9 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 444.39 us/op 583.12 us/op 0.76
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 80.951 us/op 117.70 us/op 0.69
BLS verify - blst-native 1.3163 ms/op 1.3822 ms/op 0.95
BLS verifyMultipleSignatures 3 - blst-native 2.7551 ms/op 2.9961 ms/op 0.92
BLS verifyMultipleSignatures 8 - blst-native 6.0450 ms/op 6.3564 ms/op 0.95
BLS verifyMultipleSignatures 32 - blst-native 22.122 ms/op 23.314 ms/op 0.95
BLS verifyMultipleSignatures 64 - blst-native 43.473 ms/op 46.071 ms/op 0.94
BLS verifyMultipleSignatures 128 - blst-native 86.272 ms/op 91.869 ms/op 0.94
BLS deserializing 10000 signatures 914.99 ms/op 954.12 ms/op 0.96
BLS deserializing 100000 signatures 9.2602 s/op 9.5512 s/op 0.97
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.3622 ms/op 1.3937 ms/op 0.98
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.6200 ms/op 1.5796 ms/op 1.03
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.3641 ms/op 2.4732 ms/op 0.96
BLS verifyMultipleSignatures - same message - 64 - blst-native 4.0764 ms/op 4.0254 ms/op 1.01
BLS verifyMultipleSignatures - same message - 128 - blst-native 5.7152 ms/op 5.9082 ms/op 0.97
BLS aggregatePubkeys 32 - blst-native 25.940 us/op 26.927 us/op 0.96
BLS aggregatePubkeys 128 - blst-native 101.72 us/op 105.38 us/op 0.97
getAttestationsForBlock 35.834 ms/op 51.948 ms/op 0.69
isKnown best case - 1 super set check 315.00 ns/op 515.00 ns/op 0.61
isKnown normal case - 2 super set checks 305.00 ns/op 549.00 ns/op 0.56
isKnown worse case - 16 super set checks 302.00 ns/op 530.00 ns/op 0.57
CheckpointStateCache - add get delete 5.1790 us/op 6.2920 us/op 0.82
validate api signedAggregateAndProof - struct 2.9393 ms/op 2.9757 ms/op 0.99
validate gossip signedAggregateAndProof - struct 2.8344 ms/op 2.9886 ms/op 0.95
validate gossip attestation - vc 640000 1.3871 ms/op 1.4583 ms/op 0.95
batch validate gossip attestation - vc 640000 - chunk 32 162.04 us/op 191.64 us/op 0.85
batch validate gossip attestation - vc 640000 - chunk 64 141.67 us/op 157.55 us/op 0.90
batch validate gossip attestation - vc 640000 - chunk 128 136.60 us/op 127.62 us/op 1.07
batch validate gossip attestation - vc 640000 - chunk 256 127.61 us/op 122.82 us/op 1.04
pickEth1Vote - no votes 1.2115 ms/op 1.1986 ms/op 1.01
pickEth1Vote - max votes 8.5792 ms/op 9.3050 ms/op 0.92
pickEth1Vote - Eth1Data hashTreeRoot value x2048 14.440 ms/op 17.493 ms/op 0.83
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 24.790 ms/op 25.971 ms/op 0.95
pickEth1Vote - Eth1Data fastSerialize value x2048 566.17 us/op 535.85 us/op 1.06
pickEth1Vote - Eth1Data fastSerialize tree x2048 7.4494 ms/op 5.6151 ms/op 1.33
bytes32 toHexString 478.00 ns/op 471.00 ns/op 1.01
bytes32 Buffer.toString(hex) 276.00 ns/op 282.00 ns/op 0.98
bytes32 Buffer.toString(hex) from Uint8Array 421.00 ns/op 407.00 ns/op 1.03
bytes32 Buffer.toString(hex) + 0x 279.00 ns/op 286.00 ns/op 0.98
Object access 1 prop 0.15700 ns/op 0.14900 ns/op 1.05
Map access 1 prop 0.14500 ns/op 0.15200 ns/op 0.95
Object get x1000 7.0240 ns/op 7.1770 ns/op 0.98
Map get x1000 0.60600 ns/op 0.59000 ns/op 1.03
Object set x1000 48.951 ns/op 47.009 ns/op 1.04
Map set x1000 37.835 ns/op 38.047 ns/op 0.99
Return object 10000 times 0.23370 ns/op 0.23730 ns/op 0.98
Throw Error 10000 times 3.7408 us/op 3.8558 us/op 0.97
fastMsgIdFn sha256 / 200 bytes 3.2150 us/op 3.2360 us/op 0.99
fastMsgIdFn h32 xxhash / 200 bytes 264.00 ns/op 273.00 ns/op 0.97
fastMsgIdFn h64 xxhash / 200 bytes 333.00 ns/op 336.00 ns/op 0.99
fastMsgIdFn sha256 / 1000 bytes 11.122 us/op 11.393 us/op 0.98
fastMsgIdFn h32 xxhash / 1000 bytes 391.00 ns/op 398.00 ns/op 0.98
fastMsgIdFn h64 xxhash / 1000 bytes 402.00 ns/op 408.00 ns/op 0.99
fastMsgIdFn sha256 / 10000 bytes 102.00 us/op 103.68 us/op 0.98
fastMsgIdFn h32 xxhash / 10000 bytes 1.9000 us/op 1.8790 us/op 1.01
fastMsgIdFn h64 xxhash / 10000 bytes 1.3110 us/op 1.2880 us/op 1.02
send data - 1000 256B messages 17.912 ms/op 17.874 ms/op 1.00
send data - 1000 512B messages 25.073 ms/op 24.304 ms/op 1.03
send data - 1000 1024B messages 39.957 ms/op 38.220 ms/op 1.05
send data - 1000 1200B messages 34.418 ms/op 27.768 ms/op 1.24
send data - 1000 2048B messages 38.883 ms/op 31.330 ms/op 1.24
send data - 1000 4096B messages 37.887 ms/op 33.097 ms/op 1.14
send data - 1000 16384B messages 98.043 ms/op 74.804 ms/op 1.31
send data - 1000 65536B messages 407.26 ms/op 289.26 ms/op 1.41
enrSubnets - fastDeserialize 64 bits 1.2670 us/op 1.3010 us/op 0.97
enrSubnets - ssz BitVector 64 bits 405.00 ns/op 418.00 ns/op 0.97
enrSubnets - fastDeserialize 4 bits 166.00 ns/op 176.00 ns/op 0.94
enrSubnets - ssz BitVector 4 bits 421.00 ns/op 420.00 ns/op 1.00
prioritizePeers score -10:0 att 32-0.1 sync 2-0 98.024 us/op 101.02 us/op 0.97
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 118.56 us/op 122.38 us/op 0.97
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 157.79 us/op 160.72 us/op 0.98
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 279.24 us/op 291.56 us/op 0.96
prioritizePeers score 0:0 att 64-1 sync 4-1 327.73 us/op 341.43 us/op 0.96
array of 16000 items push then shift 1.5695 us/op 1.6238 us/op 0.97
LinkedList of 16000 items push then shift 8.7560 ns/op 9.1000 ns/op 0.96
array of 16000 items push then pop 53.626 ns/op 75.073 ns/op 0.71
LinkedList of 16000 items push then pop 8.5590 ns/op 9.0880 ns/op 0.94
array of 24000 items push then shift 2.3673 us/op 2.6106 us/op 0.91
LinkedList of 24000 items push then shift 8.7220 ns/op 9.0860 ns/op 0.96
array of 24000 items push then pop 109.52 ns/op 104.97 ns/op 1.04
LinkedList of 24000 items push then pop 8.5320 ns/op 8.8380 ns/op 0.97
intersect bitArray bitLen 8 6.6830 ns/op 7.1130 ns/op 0.94
intersect array and set length 8 55.715 ns/op 55.871 ns/op 1.00
intersect bitArray bitLen 128 31.152 ns/op 32.696 ns/op 0.95
intersect array and set length 128 750.97 ns/op 768.98 ns/op 0.98
bitArray.getTrueBitIndexes() bitLen 128 1.3650 us/op 1.4100 us/op 0.97
bitArray.getTrueBitIndexes() bitLen 248 2.3340 us/op 2.5450 us/op 0.92
bitArray.getTrueBitIndexes() bitLen 512 4.5520 us/op 5.5440 us/op 0.82
Buffer.concat 32 items 903.00 ns/op 1.0040 us/op 0.90
Uint8Array.set 32 items 1.6910 us/op 1.9320 us/op 0.88
Set add up to 64 items then delete first 4.2623 us/op 4.4205 us/op 0.96
OrderedSet add up to 64 items then delete first 5.3560 us/op 5.7201 us/op 0.94
Set add up to 64 items then delete last 4.5664 us/op 4.8833 us/op 0.94
OrderedSet add up to 64 items then delete last 5.6449 us/op 5.8816 us/op 0.96
Set add up to 64 items then delete middle 4.5282 us/op 5.0075 us/op 0.90
OrderedSet add up to 64 items then delete middle 6.9019 us/op 7.7294 us/op 0.89
Set add up to 128 items then delete first 9.1986 us/op 9.7287 us/op 0.95
OrderedSet add up to 128 items then delete first 12.055 us/op 12.997 us/op 0.93
Set add up to 128 items then delete last 9.0202 us/op 9.7631 us/op 0.92
OrderedSet add up to 128 items then delete last 11.541 us/op 12.160 us/op 0.95
Set add up to 128 items then delete middle 8.9289 us/op 9.3319 us/op 0.96
OrderedSet add up to 128 items then delete middle 16.563 us/op 17.427 us/op 0.95
Set add up to 256 items then delete first 18.508 us/op 20.038 us/op 0.92
OrderedSet add up to 256 items then delete first 24.787 us/op 26.417 us/op 0.94
Set add up to 256 items then delete last 18.008 us/op 18.651 us/op 0.97
OrderedSet add up to 256 items then delete last 22.891 us/op 24.366 us/op 0.94
Set add up to 256 items then delete middle 17.927 us/op 18.976 us/op 0.94
OrderedSet add up to 256 items then delete middle 44.209 us/op 49.181 us/op 0.90
transfer serialized Status (84 B) 1.7080 us/op 1.9100 us/op 0.89
copy serialized Status (84 B) 1.4330 us/op 1.5200 us/op 0.94
transfer serialized SignedVoluntaryExit (112 B) 1.8910 us/op 1.9610 us/op 0.96
copy serialized SignedVoluntaryExit (112 B) 1.5260 us/op 1.6180 us/op 0.94
transfer serialized ProposerSlashing (416 B) 1.9990 us/op 2.2770 us/op 0.88
copy serialized ProposerSlashing (416 B) 1.7290 us/op 2.1650 us/op 0.80
transfer serialized Attestation (485 B) 1.9750 us/op 2.8730 us/op 0.69
copy serialized Attestation (485 B) 1.7450 us/op 2.0910 us/op 0.83
transfer serialized AttesterSlashing (33232 B) 2.1470 us/op 2.2240 us/op 0.97
copy serialized AttesterSlashing (33232 B) 5.0340 us/op 5.9210 us/op 0.85
transfer serialized Small SignedBeaconBlock (128000 B) 2.4630 us/op 2.8400 us/op 0.87
copy serialized Small SignedBeaconBlock (128000 B) 12.927 us/op 19.055 us/op 0.68
transfer serialized Avg SignedBeaconBlock (200000 B) 2.7350 us/op 3.3780 us/op 0.81
copy serialized Avg SignedBeaconBlock (200000 B) 19.456 us/op 21.049 us/op 0.92
transfer serialized BlobsSidecar (524380 B) 2.9540 us/op 3.2190 us/op 0.92
copy serialized BlobsSidecar (524380 B) 84.741 us/op 84.493 us/op 1.00
transfer serialized Big SignedBeaconBlock (1000000 B) 2.9910 us/op 3.3080 us/op 0.90
copy serialized Big SignedBeaconBlock (1000000 B) 162.38 us/op 157.96 us/op 1.03
pass gossip attestations to forkchoice per slot 3.6841 ms/op 3.9287 ms/op 0.94
forkChoice updateHead vc 100000 bc 64 eq 0 662.02 us/op 690.54 us/op 0.96
forkChoice updateHead vc 600000 bc 64 eq 0 3.9879 ms/op 6.7557 ms/op 0.59
forkChoice updateHead vc 1000000 bc 64 eq 0 7.0366 ms/op 7.4590 ms/op 0.94
forkChoice updateHead vc 600000 bc 320 eq 0 4.2038 ms/op 4.6712 ms/op 0.90
forkChoice updateHead vc 600000 bc 1200 eq 0 5.4469 ms/op 4.8373 ms/op 1.13
forkChoice updateHead vc 600000 bc 7200 eq 0 5.1837 ms/op 5.5201 ms/op 0.94
forkChoice updateHead vc 600000 bc 64 eq 1000 11.281 ms/op 11.766 ms/op 0.96
forkChoice updateHead vc 600000 bc 64 eq 10000 12.784 ms/op 12.590 ms/op 1.02
forkChoice updateHead vc 600000 bc 64 eq 300000 15.894 ms/op 16.495 ms/op 0.96
computeDeltas 500000 validators 300 proto nodes 6.6228 ms/op 6.5599 ms/op 1.01
computeDeltas 500000 validators 1200 proto nodes 6.5493 ms/op 6.4195 ms/op 1.02
computeDeltas 500000 validators 7200 proto nodes 6.5101 ms/op 6.1773 ms/op 1.05
computeDeltas 750000 validators 300 proto nodes 9.7569 ms/op 9.2894 ms/op 1.05
computeDeltas 750000 validators 1200 proto nodes 9.9363 ms/op 9.4003 ms/op 1.06
computeDeltas 750000 validators 7200 proto nodes 9.7974 ms/op 9.6999 ms/op 1.01
computeDeltas 1400000 validators 300 proto nodes 18.374 ms/op 18.529 ms/op 0.99
computeDeltas 1400000 validators 1200 proto nodes 18.049 ms/op 18.587 ms/op 0.97
computeDeltas 1400000 validators 7200 proto nodes 18.397 ms/op 18.720 ms/op 0.98
computeDeltas 2100000 validators 300 proto nodes 27.112 ms/op 29.715 ms/op 0.91
computeDeltas 2100000 validators 1200 proto nodes 27.510 ms/op 30.529 ms/op 0.90
computeDeltas 2100000 validators 7200 proto nodes 26.686 ms/op 29.996 ms/op 0.89
computeProposerBoostScoreFromBalances 500000 validators 3.2026 ms/op 3.5645 ms/op 0.90
computeProposerBoostScoreFromBalances 750000 validators 3.2129 ms/op 3.6032 ms/op 0.89
computeProposerBoostScoreFromBalances 1400000 validators 3.2616 ms/op 3.5955 ms/op 0.91
computeProposerBoostScoreFromBalances 2100000 validators 3.2555 ms/op 3.4760 ms/op 0.94
altair processAttestation - 250000 vs - 7PWei normalcase 2.2392 ms/op 3.3023 ms/op 0.68
altair processAttestation - 250000 vs - 7PWei worstcase 3.3445 ms/op 4.4772 ms/op 0.75
altair processAttestation - setStatus - 1/6 committees join 135.68 us/op 153.82 us/op 0.88
altair processAttestation - setStatus - 1/3 committees join 273.20 us/op 316.53 us/op 0.86
altair processAttestation - setStatus - 1/2 committees join 368.07 us/op 406.44 us/op 0.91
altair processAttestation - setStatus - 2/3 committees join 472.46 us/op 508.91 us/op 0.93
altair processAttestation - setStatus - 4/5 committees join 663.02 us/op 738.54 us/op 0.90
altair processAttestation - setStatus - 100% committees join 779.90 us/op 828.71 us/op 0.94
altair processBlock - 250000 vs - 7PWei normalcase 8.3445 ms/op 11.198 ms/op 0.75
altair processBlock - 250000 vs - 7PWei normalcase hashState 34.460 ms/op 35.466 ms/op 0.97
altair processBlock - 250000 vs - 7PWei worstcase 41.468 ms/op 44.498 ms/op 0.93
altair processBlock - 250000 vs - 7PWei worstcase hashState 91.963 ms/op 96.796 ms/op 0.95
phase0 processBlock - 250000 vs - 7PWei normalcase 3.3007 ms/op 2.7661 ms/op 1.19
phase0 processBlock - 250000 vs - 7PWei worstcase 32.513 ms/op 34.039 ms/op 0.96
altair processEth1Data - 250000 vs - 7PWei normalcase 595.11 us/op 684.11 us/op 0.87
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 11.674 us/op 15.363 us/op 0.76
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 66.537 us/op 50.504 us/op 1.32
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 22.274 us/op 19.190 us/op 1.16
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 9.3320 us/op 13.702 us/op 0.68
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 188.17 us/op 177.36 us/op 1.06
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.6167 ms/op 1.6059 ms/op 1.01
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.4894 ms/op 2.0273 ms/op 0.73
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.6811 ms/op 1.7232 ms/op 0.98
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.9812 ms/op 4.0322 ms/op 0.99
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.6539 ms/op 2.9478 ms/op 0.90
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.7868 ms/op 7.1049 ms/op 0.81
Tree 40 250000 create 347.49 ms/op 527.86 ms/op 0.66
Tree 40 250000 get(125000) 203.54 ns/op 217.57 ns/op 0.94
Tree 40 250000 set(125000) 981.16 ns/op 1.3080 us/op 0.75
Tree 40 250000 toArray() 21.304 ms/op 26.524 ms/op 0.80
Tree 40 250000 iterate all - toArray() + loop 21.482 ms/op 25.143 ms/op 0.85
Tree 40 250000 iterate all - get(i) 67.239 ms/op 77.614 ms/op 0.87
MutableVector 250000 create 11.695 ms/op 13.706 ms/op 0.85
MutableVector 250000 get(125000) 6.6460 ns/op 6.7500 ns/op 0.98
MutableVector 250000 set(125000) 290.31 ns/op 359.65 ns/op 0.81
MutableVector 250000 toArray() 3.3151 ms/op 3.9852 ms/op 0.83
MutableVector 250000 iterate all - toArray() + loop 3.5032 ms/op 4.4759 ms/op 0.78
MutableVector 250000 iterate all - get(i) 1.5413 ms/op 1.5944 ms/op 0.97
Array 250000 create 3.2521 ms/op 4.0833 ms/op 0.80
Array 250000 clone - spread 1.2114 ms/op 1.1395 ms/op 1.06
Array 250000 get(125000) 0.59800 ns/op 0.54500 ns/op 1.10
Array 250000 set(125000) 0.67100 ns/op 0.62700 ns/op 1.07
Array 250000 iterate all - loop 90.121 us/op 85.927 us/op 1.05
effectiveBalanceIncrements clone Uint8Array 300000 27.284 us/op 47.509 us/op 0.57
effectiveBalanceIncrements clone MutableVector 300000 354.00 ns/op 307.00 ns/op 1.15
effectiveBalanceIncrements rw all Uint8Array 300000 186.13 us/op 183.76 us/op 1.01
effectiveBalanceIncrements rw all MutableVector 300000 82.389 ms/op 83.520 ms/op 0.99
phase0 afterProcessEpoch - 250000 vs - 7PWei 115.87 ms/op 120.09 ms/op 0.96
phase0 beforeProcessEpoch - 250000 vs - 7PWei 49.234 ms/op 45.785 ms/op 1.08
altair processEpoch - mainnet_e81889 510.62 ms/op 475.27 ms/op 1.07
mainnet_e81889 - altair beforeProcessEpoch 80.581 ms/op 64.893 ms/op 1.24
mainnet_e81889 - altair processJustificationAndFinalization 15.715 us/op 16.961 us/op 0.93
mainnet_e81889 - altair processInactivityUpdates 5.6345 ms/op 5.5723 ms/op 1.01
mainnet_e81889 - altair processRewardsAndPenalties 54.436 ms/op 66.681 ms/op 0.82
mainnet_e81889 - altair processRegistryUpdates 2.3500 us/op 2.7380 us/op 0.86
mainnet_e81889 - altair processSlashings 431.00 ns/op 521.00 ns/op 0.83
mainnet_e81889 - altair processEth1DataReset 476.00 ns/op 480.00 ns/op 0.99
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.2714 ms/op 1.3263 ms/op 0.96
mainnet_e81889 - altair processSlashingsReset 5.4730 us/op 4.1350 us/op 1.32
mainnet_e81889 - altair processRandaoMixesReset 5.4660 us/op 5.1810 us/op 1.06
mainnet_e81889 - altair processHistoricalRootsUpdate 615.00 ns/op 888.00 ns/op 0.69
mainnet_e81889 - altair processParticipationFlagUpdates 2.1420 us/op 2.3780 us/op 0.90
mainnet_e81889 - altair processSyncCommitteeUpdates 575.00 ns/op 479.00 ns/op 1.20
mainnet_e81889 - altair afterProcessEpoch 119.98 ms/op 128.63 ms/op 0.93
capella processEpoch - mainnet_e217614 1.9170 s/op 1.6809 s/op 1.14
mainnet_e217614 - capella beforeProcessEpoch 462.56 ms/op 298.56 ms/op 1.55
mainnet_e217614 - capella processJustificationAndFinalization 19.121 us/op 22.578 us/op 0.85
mainnet_e217614 - capella processInactivityUpdates 15.777 ms/op 19.373 ms/op 0.81
mainnet_e217614 - capella processRewardsAndPenalties 484.63 ms/op 312.08 ms/op 1.55
mainnet_e217614 - capella processRegistryUpdates 16.822 us/op 24.886 us/op 0.68
mainnet_e217614 - capella processSlashings 417.00 ns/op 748.00 ns/op 0.56
mainnet_e217614 - capella processEth1DataReset 402.00 ns/op 815.00 ns/op 0.49
mainnet_e217614 - capella processEffectiveBalanceUpdates 4.0610 ms/op 4.7555 ms/op 0.85
mainnet_e217614 - capella processSlashingsReset 3.0090 us/op 4.6990 us/op 0.64
mainnet_e217614 - capella processRandaoMixesReset 4.7820 us/op 5.0260 us/op 0.95
mainnet_e217614 - capella processHistoricalRootsUpdate 600.00 ns/op 1.1840 us/op 0.51
mainnet_e217614 - capella processParticipationFlagUpdates 1.3750 us/op 3.0300 us/op 0.45
mainnet_e217614 - capella afterProcessEpoch 299.14 ms/op 331.75 ms/op 0.90
phase0 processEpoch - mainnet_e58758 402.64 ms/op 465.93 ms/op 0.86
mainnet_e58758 - phase0 beforeProcessEpoch 118.60 ms/op 133.41 ms/op 0.89
mainnet_e58758 - phase0 processJustificationAndFinalization 14.853 us/op 21.439 us/op 0.69
mainnet_e58758 - phase0 processRewardsAndPenalties 61.893 ms/op 50.358 ms/op 1.23
mainnet_e58758 - phase0 processRegistryUpdates 9.4040 us/op 17.932 us/op 0.52
mainnet_e58758 - phase0 processSlashings 495.00 ns/op 842.00 ns/op 0.59
mainnet_e58758 - phase0 processEth1DataReset 408.00 ns/op 660.00 ns/op 0.62
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 995.35 us/op 1.3169 ms/op 0.76
mainnet_e58758 - phase0 processSlashingsReset 2.2820 us/op 3.1090 us/op 0.73
mainnet_e58758 - phase0 processRandaoMixesReset 4.1730 us/op 7.1340 us/op 0.58
mainnet_e58758 - phase0 processHistoricalRootsUpdate 406.00 ns/op 970.00 ns/op 0.42
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.1190 us/op 7.4340 us/op 0.55
mainnet_e58758 - phase0 afterProcessEpoch 96.259 ms/op 117.26 ms/op 0.82
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.2459 ms/op 1.6556 ms/op 0.75
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4409 ms/op 1.7211 ms/op 0.84
altair processInactivityUpdates - 250000 normalcase 19.478 ms/op 20.924 ms/op 0.93
altair processInactivityUpdates - 250000 worstcase 22.629 ms/op 28.923 ms/op 0.78
phase0 processRegistryUpdates - 250000 normalcase 9.6080 us/op 13.538 us/op 0.71
phase0 processRegistryUpdates - 250000 badcase_full_deposits 358.12 us/op 459.92 us/op 0.78
phase0 processRegistryUpdates - 250000 worstcase 0.5 115.74 ms/op 168.78 ms/op 0.69
altair processRewardsAndPenalties - 250000 normalcase 63.679 ms/op 76.402 ms/op 0.83
altair processRewardsAndPenalties - 250000 worstcase 62.197 ms/op 81.344 ms/op 0.76
phase0 getAttestationDeltas - 250000 normalcase 8.0719 ms/op 14.980 ms/op 0.54
phase0 getAttestationDeltas - 250000 worstcase 8.0437 ms/op 13.532 ms/op 0.59
phase0 processSlashings - 250000 worstcase 2.2785 ms/op 2.8197 ms/op 0.81
altair processSyncCommitteeUpdates - 250000 147.37 ms/op 185.99 ms/op 0.79
BeaconState.hashTreeRoot - No change 261.00 ns/op 302.00 ns/op 0.86
BeaconState.hashTreeRoot - 1 full validator 107.02 us/op 154.87 us/op 0.69
BeaconState.hashTreeRoot - 32 full validator 1.1199 ms/op 1.5939 ms/op 0.70
BeaconState.hashTreeRoot - 512 full validator 12.112 ms/op 16.715 ms/op 0.72
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 131.36 us/op 161.59 us/op 0.81
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.7614 ms/op 2.3169 ms/op 0.76
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 22.251 ms/op 30.308 ms/op 0.73
BeaconState.hashTreeRoot - 1 balances 104.62 us/op 154.22 us/op 0.68
BeaconState.hashTreeRoot - 32 balances 996.60 us/op 1.3045 ms/op 0.76
BeaconState.hashTreeRoot - 512 balances 9.1949 ms/op 13.723 ms/op 0.67
BeaconState.hashTreeRoot - 250000 balances 168.24 ms/op 200.63 ms/op 0.84
aggregationBits - 2048 els - zipIndexesInBitList 49.412 us/op 26.498 us/op 1.86
byteArrayEquals 32 51.027 ns/op
Buffer.compare 32 56.379 ns/op
byteArrayEquals 1024 1.4730 us/op
Buffer.compare 1024 70.807 ns/op
byteArrayEquals 16384 23.789 us/op
Buffer.compare 16384 282.37 ns/op
byteArrayEquals 123687377 178.81 ms/op
Buffer.compare 123687377 6.2747 ms/op
byteArrayEquals 32 - diff last byte 51.131 ns/op
Buffer.compare 32 - diff last byte 62.767 ns/op
byteArrayEquals 1024 - diff last byte 1.5034 us/op
Buffer.compare 1024 - diff last byte 73.195 ns/op
byteArrayEquals 16384 - diff last byte 23.935 us/op
Buffer.compare 16384 - diff last byte 284.73 ns/op
byteArrayEquals 123687377 - diff last byte 180.44 ms/op
Buffer.compare 123687377 - diff last byte 6.2568 ms/op
byteArrayEquals 32 - random bytes 6.0210 ns/op
Buffer.compare 32 - random bytes 62.432 ns/op
byteArrayEquals 1024 - random bytes 5.9290 ns/op
Buffer.compare 1024 - random bytes 62.437 ns/op
byteArrayEquals 16384 - random bytes 5.9860 ns/op
Buffer.compare 16384 - random bytes 61.941 ns/op
byteArrayEquals 123687377 - random bytes 9.2500 ns/op
Buffer.compare 123687377 - random bytes 65.110 ns/op
regular array get 100000 times 33.441 us/op 35.165 us/op 0.95
wrappedArray get 100000 times 33.448 us/op 38.953 us/op 0.86
arrayWithProxy get 100000 times 14.345 ms/op 16.819 ms/op 0.85
ssz.Root.equals 51.500 ns/op 309.00 ns/op 0.17
byteArrayEquals 50.478 ns/op 330.00 ns/op 0.15
Buffer.compare 11.143 ns/op
shuffle list - 16384 els 7.0596 ms/op 9.1379 ms/op 0.77
shuffle list - 250000 els 103.51 ms/op 118.48 ms/op 0.87
processSlot - 1 slots 17.254 us/op 22.220 us/op 0.78
processSlot - 32 slots 2.5353 ms/op 4.0167 ms/op 0.63
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 54.442 ms/op 67.826 ms/op 0.80
getCommitteeAssignments - req 1 vs - 250000 vc 2.5276 ms/op 3.0161 ms/op 0.84
getCommitteeAssignments - req 100 vs - 250000 vc 3.7591 ms/op 4.7955 ms/op 0.78
getCommitteeAssignments - req 1000 vs - 250000 vc 4.0995 ms/op 4.6978 ms/op 0.87
findModifiedValidators - 10000 modified validators 564.98 ms/op
findModifiedValidators - 1000 modified validators 460.13 ms/op
findModifiedValidators - 100 modified validators 445.24 ms/op
findModifiedValidators - 10 modified validators 474.61 ms/op
findModifiedValidators - 1 modified validators 425.30 ms/op
findModifiedValidators - no difference 447.40 ms/op
compare ViewDUs 5.2399 s/op
compare each validator Uint8Array 1.8726 s/op
compare ViewDU to Uint8Array 1.5162 s/op
migrate state 1000000 validators, 24 modified, 0 new 947.60 ms/op
migrate state 1000000 validators, 1700 modified, 1000 new 1.2247 s/op
migrate state 1000000 validators, 3400 modified, 2000 new 1.1968 s/op
migrate state 1500000 validators, 24 modified, 0 new 724.80 ms/op
migrate state 1500000 validators, 1700 modified, 1000 new 1.0023 s/op
migrate state 1500000 validators, 3400 modified, 2000 new 1.2762 s/op
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.5300 ns/op 5.9600 ns/op 0.76
state getBlockRootAtSlot - 250000 vs - 7PWei 544.92 ns/op 736.92 ns/op 0.74
computeProposers - vc 250000 9.2031 ms/op 10.610 ms/op 0.87
computeEpochShuffling - vc 250000 106.36 ms/op 122.79 ms/op 0.87
getNextSyncCommittee - vc 250000 155.64 ms/op 178.23 ms/op 0.87
computeSigningRoot for AttestationData 21.090 us/op 31.628 us/op 0.67
hash AttestationData serialized data then Buffer.toString(base64) 2.3140 us/op 2.5459 us/op 0.91
toHexString serialized data 1.0706 us/op 1.3307 us/op 0.80
Buffer.toString(base64) 215.79 ns/op 263.76 ns/op 0.82

by benchmarkbot/action

@twoeths twoeths marked this pull request as ready for review October 23, 2023 06:47
@twoeths twoeths requested a review from a team as a code owner October 23, 2023 06:47
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.

Generally look good! Some minor comments

const currentShufflingDecisionBlock = getShufflingDecisionBlock(state, currentEpoch);
const currentShufflingIn = opts?.shufflingGetter?.(currentEpoch, currentShufflingDecisionBlock);
const nextShufflingDecisionBlock = getShufflingDecisionBlock(state, nextEpoch);
const nextShufflingIn = opts?.shufflingGetter?.(nextEpoch, nextShufflingDecisionBlock);
Copy link
Contributor

Choose a reason for hiding this comment

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

What does the In suffix mean? Can you comment above this block detailing the rationale and purpose of these lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

those are shufflings comeing from ShufflingCache provided by BeaconChain. Will refactor to cachedNextShuffling and add more comments 👍

seedValidator: CompositeViewDU<typeof ssz.phase0.Validator>,
newValidatorBytes: Uint8Array
): CompositeViewDU<typeof ssz.phase0.Validator> {
if (isSameValidator(seedValidator, newValidatorBytes)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Extend this checks for the 3 cases: same pk, same withdrawals_creds, and same pk + same withdrawals_creds

* ✔ byteArrayEquals 123687377 3.077884 ops/s 324.8985 ms/op - 1 runs 64.5 s
* ✔ Buffer.compare 123687377 114.7834 ops/s 8.712061 ms/op - 13 runs 12.1 s
*/
describe("compare Uint8Array", () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

You should extend this comparision tests to various checks:

  • compare equal byte arrays
  • compare byte arrays different at all bytes (2 rand arrays)
  • compare byte arrays different only on the last byte

for (let i = 0; i < validatorCount; i++) {
const validator = validators[i];

// Note: Not usable for fork-choice balances since in-active validators are not zero'ed
effectiveBalanceIncrements[i] = Math.floor(validator.effectiveBalance / EFFECTIVE_BALANCE_INCREMENT);

if (isActiveValidator(validator, previousEpoch)) {
if (previousShufflingIn == null && isActiveValidator(validator, previousEpoch)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you detail more the motivation of this change?

@twoeths twoeths requested a review from dapplion October 27, 2023 06:16
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 good! Let's heavy test on the next PR round

@twoeths twoeths merged commit b11fe2d into unstable Oct 31, 2023
15 checks passed
@twoeths twoeths deleted the tuyen/load_state branch October 31, 2023 02:05
@twoeths
Copy link
Contributor Author

twoeths commented Oct 31, 2023

@naviechan will coordinate with you on #6042

@wemeetagain
Copy link
Member

🎉 This PR is included in v1.12.0 🎉

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.

3 participants