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

refactor: use for...of instead of forEach #6307

Merged
merged 1 commit into from
Jan 16, 2024

Conversation

nflaig
Copy link
Member

@nflaig nflaig commented Jan 16, 2024

Motivation

Code consistency, marginal performance improvements. I just watched video about node performance yesterday and it was brought up how bad forEach actually is especially if you iterate huge data sets, took this as a inspiration to give our forEach usage another review. We don't use it a lot but might as well clean up remaining forEach usage.

Description

Use for...of instead of forEach

Note: I did not update all occasions as it's either not relevant there in terms of performance or it is just a neat usage of forEach where for...of would make the code less readable.

There was plenty of previous work done by Lion related to this

@nflaig nflaig requested a review from a team as a code owner January 16, 2024 11:00
Copy link

codecov bot commented Jan 16, 2024

Codecov Report

Merging #6307 (587ea9f) into unstable (4ff2911) will decrease coverage by 0.01%.
The diff coverage is n/a.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #6307      +/-   ##
============================================
- Coverage     80.38%   80.37%   -0.01%     
============================================
  Files           202      202              
  Lines         19620    19622       +2     
  Branches       1176     1176              
============================================
  Hits          15771    15771              
- Misses         3821     3823       +2     
  Partials         28       28              

Copy link
Contributor

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 11df56b Previous: 4ff2911 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 530.02 us/op 790.42 us/op 0.67
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 88.015 us/op 80.935 us/op 1.09
BLS verify - blst-native 1.3502 ms/op 1.3015 ms/op 1.04
BLS verifyMultipleSignatures 3 - blst-native 2.8763 ms/op 2.7542 ms/op 1.04
BLS verifyMultipleSignatures 8 - blst-native 6.2033 ms/op 6.1017 ms/op 1.02
BLS verifyMultipleSignatures 32 - blst-native 22.649 ms/op 22.375 ms/op 1.01
BLS verifyMultipleSignatures 64 - blst-native 44.284 ms/op 43.855 ms/op 1.01
BLS verifyMultipleSignatures 128 - blst-native 87.741 ms/op 86.832 ms/op 1.01
BLS deserializing 10000 signatures 954.03 ms/op 928.19 ms/op 1.03
BLS deserializing 100000 signatures 9.6614 s/op 9.3938 s/op 1.03
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.3645 ms/op 1.3394 ms/op 1.02
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.6702 ms/op 1.5185 ms/op 1.10
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.4055 ms/op 2.3234 ms/op 1.04
BLS verifyMultipleSignatures - same message - 64 - blst-native 4.4692 ms/op 4.4427 ms/op 1.01
BLS verifyMultipleSignatures - same message - 128 - blst-native 7.7290 ms/op 7.8803 ms/op 0.98
BLS aggregatePubkeys 32 - blst-native 28.236 us/op 26.029 us/op 1.08
BLS aggregatePubkeys 128 - blst-native 103.71 us/op 100.23 us/op 1.03
getAttestationsForBlock 56.773 ms/op 49.463 ms/op 1.15
getSlashingsAndExits - default max 247.86 us/op 158.89 us/op 1.56
getSlashingsAndExits - 2k 459.55 us/op 370.92 us/op 1.24
proposeBlockBody type=full, size=empty 5.2648 ms/op 4.9057 ms/op 1.07
isKnown best case - 1 super set check 341.00 ns/op 320.00 ns/op 1.07
isKnown normal case - 2 super set checks 352.00 ns/op 314.00 ns/op 1.12
isKnown worse case - 16 super set checks 332.00 ns/op 309.00 ns/op 1.07
CheckpointStateCache - add get delete 5.5940 us/op 5.8350 us/op 0.96
validate api signedAggregateAndProof - struct 2.9275 ms/op 2.7171 ms/op 1.08
validate gossip signedAggregateAndProof - struct 2.8890 ms/op 2.7186 ms/op 1.06
validate gossip attestation - vc 640000 1.3977 ms/op 1.3136 ms/op 1.06
batch validate gossip attestation - vc 640000 - chunk 32 168.15 us/op 156.85 us/op 1.07
batch validate gossip attestation - vc 640000 - chunk 64 149.96 us/op 143.75 us/op 1.04
batch validate gossip attestation - vc 640000 - chunk 128 150.38 us/op 131.74 us/op 1.14
batch validate gossip attestation - vc 640000 - chunk 256 142.75 us/op 128.63 us/op 1.11
pickEth1Vote - no votes 1.3491 ms/op 1.2189 ms/op 1.11
pickEth1Vote - max votes 12.229 ms/op 10.697 ms/op 1.14
pickEth1Vote - Eth1Data hashTreeRoot value x2048 20.333 ms/op 18.045 ms/op 1.13
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 28.285 ms/op 26.088 ms/op 1.08
pickEth1Vote - Eth1Data fastSerialize value x2048 713.19 us/op 575.92 us/op 1.24
pickEth1Vote - Eth1Data fastSerialize tree x2048 5.7388 ms/op 6.1417 ms/op 0.93
bytes32 toHexString 707.00 ns/op 476.00 ns/op 1.49
bytes32 Buffer.toString(hex) 316.00 ns/op 274.00 ns/op 1.15
bytes32 Buffer.toString(hex) from Uint8Array 563.00 ns/op 395.00 ns/op 1.43
bytes32 Buffer.toString(hex) + 0x 307.00 ns/op 275.00 ns/op 1.12
Object access 1 prop 0.19600 ns/op 0.14800 ns/op 1.32
Map access 1 prop 0.14900 ns/op 0.13800 ns/op 1.08
Object get x1000 7.8990 ns/op 7.3300 ns/op 1.08
Map get x1000 0.85100 ns/op 0.70200 ns/op 1.21
Object set x1000 56.442 ns/op 47.136 ns/op 1.20
Map set x1000 42.726 ns/op 36.368 ns/op 1.17
Return object 10000 times 0.25550 ns/op 0.22460 ns/op 1.14
Throw Error 10000 times 4.0701 us/op 3.6671 us/op 1.11
fastMsgIdFn sha256 / 200 bytes 3.4660 us/op 3.1190 us/op 1.11
fastMsgIdFn h32 xxhash / 200 bytes 322.00 ns/op 275.00 ns/op 1.17
fastMsgIdFn h64 xxhash / 200 bytes 360.00 ns/op 337.00 ns/op 1.07
fastMsgIdFn sha256 / 1000 bytes 11.956 us/op 10.823 us/op 1.10
fastMsgIdFn h32 xxhash / 1000 bytes 456.00 ns/op 396.00 ns/op 1.15
fastMsgIdFn h64 xxhash / 1000 bytes 434.00 ns/op 393.00 ns/op 1.10
fastMsgIdFn sha256 / 10000 bytes 105.40 us/op 99.559 us/op 1.06
fastMsgIdFn h32 xxhash / 10000 bytes 2.1460 us/op 1.8430 us/op 1.16
fastMsgIdFn h64 xxhash / 10000 bytes 1.5020 us/op 1.2710 us/op 1.18
send data - 1000 256B messages 20.484 ms/op 17.545 ms/op 1.17
send data - 1000 512B messages 31.737 ms/op 25.348 ms/op 1.25
send data - 1000 1024B messages 43.980 ms/op 39.271 ms/op 1.12
send data - 1000 1200B messages 37.655 ms/op 37.281 ms/op 1.01
send data - 1000 2048B messages 46.579 ms/op 42.997 ms/op 1.08
send data - 1000 4096B messages 43.493 ms/op 40.091 ms/op 1.08
send data - 1000 16384B messages 116.29 ms/op 115.93 ms/op 1.00
send data - 1000 65536B messages 466.88 ms/op 451.35 ms/op 1.03
enrSubnets - fastDeserialize 64 bits 1.2450 us/op 1.2390 us/op 1.00
enrSubnets - ssz BitVector 64 bits 458.00 ns/op 418.00 ns/op 1.10
enrSubnets - fastDeserialize 4 bits 170.00 ns/op 173.00 ns/op 0.98
enrSubnets - ssz BitVector 4 bits 449.00 ns/op 409.00 ns/op 1.10
prioritizePeers score -10:0 att 32-0.1 sync 2-0 110.86 us/op 98.759 us/op 1.12
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 133.43 us/op 119.74 us/op 1.11
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 174.50 us/op 155.55 us/op 1.12
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 308.48 us/op 278.17 us/op 1.11
prioritizePeers score 0:0 att 64-1 sync 4-1 354.22 us/op 324.54 us/op 1.09
array of 16000 items push then shift 1.6809 us/op 1.5390 us/op 1.09
LinkedList of 16000 items push then shift 9.2180 ns/op 8.6190 ns/op 1.07
array of 16000 items push then pop 97.897 ns/op 72.656 ns/op 1.35
LinkedList of 16000 items push then pop 8.9010 ns/op 8.3760 ns/op 1.06
array of 24000 items push then shift 2.5355 us/op 2.2840 us/op 1.11
LinkedList of 24000 items push then shift 9.0940 ns/op 8.5720 ns/op 1.06
array of 24000 items push then pop 134.10 ns/op 110.05 ns/op 1.22
LinkedList of 24000 items push then pop 8.8620 ns/op 8.3110 ns/op 1.07
intersect bitArray bitLen 8 6.5130 ns/op 6.1340 ns/op 1.06
intersect array and set length 8 64.467 ns/op 60.318 ns/op 1.07
intersect bitArray bitLen 128 34.338 ns/op 32.565 ns/op 1.05
intersect array and set length 128 891.07 ns/op 816.37 ns/op 1.09
bitArray.getTrueBitIndexes() bitLen 128 1.6020 us/op 1.4100 us/op 1.14
bitArray.getTrueBitIndexes() bitLen 248 2.6390 us/op 2.3900 us/op 1.10
bitArray.getTrueBitIndexes() bitLen 512 5.0070 us/op 4.7750 us/op 1.05
Buffer.concat 32 items 993.00 ns/op 959.00 ns/op 1.04
Uint8Array.set 32 items 1.6920 us/op 1.9970 us/op 0.85
Set add up to 64 items then delete first 4.4586 us/op 4.2766 us/op 1.04
OrderedSet add up to 64 items then delete first 5.6663 us/op 5.3239 us/op 1.06
Set add up to 64 items then delete last 4.7177 us/op 4.4071 us/op 1.07
OrderedSet add up to 64 items then delete last 5.9623 us/op 5.4437 us/op 1.10
Set add up to 64 items then delete middle 4.5819 us/op 4.3592 us/op 1.05
OrderedSet add up to 64 items then delete middle 7.1378 us/op 6.6675 us/op 1.07
Set add up to 128 items then delete first 9.3944 us/op 8.8194 us/op 1.07
OrderedSet add up to 128 items then delete first 12.594 us/op 12.050 us/op 1.05
Set add up to 128 items then delete last 9.3542 us/op 8.9694 us/op 1.04
OrderedSet add up to 128 items then delete last 11.862 us/op 11.249 us/op 1.05
Set add up to 128 items then delete middle 9.3073 us/op 8.9656 us/op 1.04
OrderedSet add up to 128 items then delete middle 17.176 us/op 16.603 us/op 1.03
Set add up to 256 items then delete first 19.054 us/op 18.457 us/op 1.03
OrderedSet add up to 256 items then delete first 25.833 us/op 24.903 us/op 1.04
Set add up to 256 items then delete last 18.678 us/op 17.955 us/op 1.04
OrderedSet add up to 256 items then delete last 23.718 us/op 22.709 us/op 1.04
Set add up to 256 items then delete middle 18.538 us/op 17.827 us/op 1.04
OrderedSet add up to 256 items then delete middle 45.810 us/op 44.808 us/op 1.02
transfer serialized Status (84 B) 1.7700 us/op 1.7300 us/op 1.02
copy serialized Status (84 B) 1.4760 us/op 1.4500 us/op 1.02
transfer serialized SignedVoluntaryExit (112 B) 1.8550 us/op 1.9570 us/op 0.95
copy serialized SignedVoluntaryExit (112 B) 1.5150 us/op 1.6090 us/op 0.94
transfer serialized ProposerSlashing (416 B) 2.0320 us/op 3.0070 us/op 0.68
copy serialized ProposerSlashing (416 B) 1.8430 us/op 2.9280 us/op 0.63
transfer serialized Attestation (485 B) 2.0350 us/op 3.1300 us/op 0.65
copy serialized Attestation (485 B) 2.1080 us/op 2.9280 us/op 0.72
transfer serialized AttesterSlashing (33232 B) 2.5010 us/op 3.0570 us/op 0.82
copy serialized AttesterSlashing (33232 B) 5.9630 us/op 6.0850 us/op 0.98
transfer serialized Small SignedBeaconBlock (128000 B) 3.0140 us/op 3.1580 us/op 0.95
copy serialized Small SignedBeaconBlock (128000 B) 15.259 us/op 14.113 us/op 1.08
transfer serialized Avg SignedBeaconBlock (200000 B) 2.9380 us/op 3.5600 us/op 0.83
copy serialized Avg SignedBeaconBlock (200000 B) 23.073 us/op 20.032 us/op 1.15
transfer serialized BlobsSidecar (524380 B) 3.0800 us/op 3.3220 us/op 0.93
copy serialized BlobsSidecar (524380 B) 84.332 us/op 81.919 us/op 1.03
transfer serialized Big SignedBeaconBlock (1000000 B) 3.2440 us/op 3.6740 us/op 0.88
copy serialized Big SignedBeaconBlock (1000000 B) 155.32 us/op 148.79 us/op 1.04
pass gossip attestations to forkchoice per slot 4.1359 ms/op 3.8246 ms/op 1.08
forkChoice updateHead vc 100000 bc 64 eq 0 690.67 us/op 660.19 us/op 1.05
forkChoice updateHead vc 600000 bc 64 eq 0 4.7980 ms/op 4.4605 ms/op 1.08
forkChoice updateHead vc 1000000 bc 64 eq 0 7.3956 ms/op 6.9217 ms/op 1.07
forkChoice updateHead vc 600000 bc 320 eq 0 4.1846 ms/op 4.1475 ms/op 1.01
forkChoice updateHead vc 600000 bc 1200 eq 0 4.3920 ms/op 4.2859 ms/op 1.02
forkChoice updateHead vc 600000 bc 7200 eq 0 5.5275 ms/op 5.1188 ms/op 1.08
forkChoice updateHead vc 600000 bc 64 eq 1000 11.663 ms/op 11.180 ms/op 1.04
forkChoice updateHead vc 600000 bc 64 eq 10000 12.346 ms/op 11.816 ms/op 1.04
forkChoice updateHead vc 600000 bc 64 eq 300000 16.137 ms/op 15.579 ms/op 1.04
computeDeltas 500000 validators 300 proto nodes 6.8780 ms/op 6.5100 ms/op 1.06
computeDeltas 500000 validators 1200 proto nodes 6.8730 ms/op 6.3606 ms/op 1.08
computeDeltas 500000 validators 7200 proto nodes 6.8034 ms/op 6.3198 ms/op 1.08
computeDeltas 750000 validators 300 proto nodes 10.291 ms/op 9.2726 ms/op 1.11
computeDeltas 750000 validators 1200 proto nodes 10.237 ms/op 9.3949 ms/op 1.09
computeDeltas 750000 validators 7200 proto nodes 10.297 ms/op 9.4504 ms/op 1.09
computeDeltas 1400000 validators 300 proto nodes 19.548 ms/op 18.846 ms/op 1.04
computeDeltas 1400000 validators 1200 proto nodes 19.157 ms/op 18.823 ms/op 1.02
computeDeltas 1400000 validators 7200 proto nodes 19.494 ms/op 18.532 ms/op 1.05
computeDeltas 2100000 validators 300 proto nodes 28.609 ms/op 28.620 ms/op 1.00
computeDeltas 2100000 validators 1200 proto nodes 29.101 ms/op 27.150 ms/op 1.07
computeDeltas 2100000 validators 7200 proto nodes 28.991 ms/op 27.829 ms/op 1.04
computeProposerBoostScoreFromBalances 500000 validators 3.8599 ms/op 3.6500 ms/op 1.06
computeProposerBoostScoreFromBalances 750000 validators 3.8075 ms/op 3.5938 ms/op 1.06
computeProposerBoostScoreFromBalances 1400000 validators 3.8884 ms/op 3.5832 ms/op 1.09
computeProposerBoostScoreFromBalances 2100000 validators 3.8527 ms/op 3.6292 ms/op 1.06
altair processAttestation - 250000 vs - 7PWei normalcase 2.6025 ms/op 2.0451 ms/op 1.27
altair processAttestation - 250000 vs - 7PWei worstcase 3.5143 ms/op 3.0241 ms/op 1.16
altair processAttestation - setStatus - 1/6 committees join 205.62 us/op 139.07 us/op 1.48
altair processAttestation - setStatus - 1/3 committees join 347.91 us/op 272.95 us/op 1.27
altair processAttestation - setStatus - 1/2 committees join 477.30 us/op 371.71 us/op 1.28
altair processAttestation - setStatus - 2/3 committees join 588.40 us/op 457.49 us/op 1.29
altair processAttestation - setStatus - 4/5 committees join 800.70 us/op 655.43 us/op 1.22
altair processAttestation - setStatus - 100% committees join 935.06 us/op 758.18 us/op 1.23
altair processBlock - 250000 vs - 7PWei normalcase 9.8438 ms/op 9.7957 ms/op 1.00
altair processBlock - 250000 vs - 7PWei normalcase hashState 32.868 ms/op 33.317 ms/op 0.99
altair processBlock - 250000 vs - 7PWei worstcase 39.984 ms/op 35.864 ms/op 1.11
altair processBlock - 250000 vs - 7PWei worstcase hashState 92.185 ms/op 88.727 ms/op 1.04
phase0 processBlock - 250000 vs - 7PWei normalcase 2.9493 ms/op 2.4592 ms/op 1.20
phase0 processBlock - 250000 vs - 7PWei worstcase 31.095 ms/op 30.141 ms/op 1.03
altair processEth1Data - 250000 vs - 7PWei normalcase 552.44 us/op 503.90 us/op 1.10
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 13.151 us/op 12.199 us/op 1.08
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 62.304 us/op 57.078 us/op 1.09
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 23.186 us/op 10.631 us/op 2.18
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 7.3980 us/op 9.6820 us/op 0.76
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 165.47 us/op 130.14 us/op 1.27
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.4661 ms/op 1.0699 ms/op 1.37
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.9792 ms/op 1.5594 ms/op 1.27
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.6736 ms/op 1.5198 ms/op 1.10
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.4155 ms/op 3.2428 ms/op 1.05
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.9434 ms/op 2.2669 ms/op 1.30
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.4531 ms/op 4.4695 ms/op 1.22
Tree 40 250000 create 368.63 ms/op 336.21 ms/op 1.10
Tree 40 250000 get(125000) 213.44 ns/op 197.93 ns/op 1.08
Tree 40 250000 set(125000) 1.1041 us/op 978.60 ns/op 1.13
Tree 40 250000 toArray() 21.001 ms/op 18.555 ms/op 1.13
Tree 40 250000 iterate all - toArray() + loop 22.403 ms/op 18.713 ms/op 1.20
Tree 40 250000 iterate all - get(i) 65.966 ms/op 64.208 ms/op 1.03
MutableVector 250000 create 12.871 ms/op 13.648 ms/op 0.94
MutableVector 250000 get(125000) 6.7190 ns/op 6.3780 ns/op 1.05
MutableVector 250000 set(125000) 296.68 ns/op 267.42 ns/op 1.11
MutableVector 250000 toArray() 3.7945 ms/op 2.9909 ms/op 1.27
MutableVector 250000 iterate all - toArray() + loop 4.2398 ms/op 3.6905 ms/op 1.15
MutableVector 250000 iterate all - get(i) 1.5498 ms/op 1.8969 ms/op 0.82
Array 250000 create 3.4444 ms/op 2.7935 ms/op 1.23
Array 250000 clone - spread 1.3908 ms/op 1.2348 ms/op 1.13
Array 250000 get(125000) 1.1290 ns/op 1.0270 ns/op 1.10
Array 250000 set(125000) 4.3000 ns/op 4.0590 ns/op 1.06
Array 250000 iterate all - loop 168.00 us/op 163.76 us/op 1.03
effectiveBalanceIncrements clone Uint8Array 300000 40.935 us/op 26.326 us/op 1.55
effectiveBalanceIncrements clone MutableVector 300000 414.00 ns/op 364.00 ns/op 1.14
effectiveBalanceIncrements rw all Uint8Array 300000 203.22 us/op 197.45 us/op 1.03
effectiveBalanceIncrements rw all MutableVector 300000 95.094 ms/op 80.961 ms/op 1.17
phase0 afterProcessEpoch - 250000 vs - 7PWei 127.56 ms/op 111.13 ms/op 1.15
phase0 beforeProcessEpoch - 250000 vs - 7PWei 40.334 ms/op 51.951 ms/op 0.78
altair processEpoch - mainnet_e81889 546.12 ms/op 496.82 ms/op 1.10
mainnet_e81889 - altair beforeProcessEpoch 93.031 ms/op 80.107 ms/op 1.16
mainnet_e81889 - altair processJustificationAndFinalization 18.747 us/op 14.500 us/op 1.29
mainnet_e81889 - altair processInactivityUpdates 5.6433 ms/op 5.4021 ms/op 1.04
mainnet_e81889 - altair processRewardsAndPenalties 61.615 ms/op 60.038 ms/op 1.03
mainnet_e81889 - altair processRegistryUpdates 3.2980 us/op 2.5020 us/op 1.32
mainnet_e81889 - altair processSlashings 401.00 ns/op 426.00 ns/op 0.94
mainnet_e81889 - altair processEth1DataReset 574.00 ns/op 426.00 ns/op 1.35
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.4467 ms/op 1.4261 ms/op 1.01
mainnet_e81889 - altair processSlashingsReset 3.3750 us/op 3.6460 us/op 0.93
mainnet_e81889 - altair processRandaoMixesReset 5.1270 us/op 5.0450 us/op 1.02
mainnet_e81889 - altair processHistoricalRootsUpdate 893.00 ns/op 599.00 ns/op 1.49
mainnet_e81889 - altair processParticipationFlagUpdates 2.2240 us/op 2.0950 us/op 1.06
mainnet_e81889 - altair processSyncCommitteeUpdates 639.00 ns/op 556.00 ns/op 1.15
mainnet_e81889 - altair afterProcessEpoch 120.42 ms/op 115.28 ms/op 1.04
capella processEpoch - mainnet_e217614 2.5122 s/op 2.1276 s/op 1.18
mainnet_e217614 - capella beforeProcessEpoch 570.77 ms/op 508.01 ms/op 1.12
mainnet_e217614 - capella processJustificationAndFinalization 17.479 us/op 22.100 us/op 0.79
mainnet_e217614 - capella processInactivityUpdates 18.615 ms/op 23.811 ms/op 0.78
mainnet_e217614 - capella processRewardsAndPenalties 419.81 ms/op 401.69 ms/op 1.05
mainnet_e217614 - capella processRegistryUpdates 25.208 us/op 29.402 us/op 0.86
mainnet_e217614 - capella processSlashings 1.5370 us/op 551.00 ns/op 2.79
mainnet_e217614 - capella processEth1DataReset 399.00 ns/op 516.00 ns/op 0.77
mainnet_e217614 - capella processEffectiveBalanceUpdates 10.474 ms/op 4.7723 ms/op 2.19
mainnet_e217614 - capella processSlashingsReset 3.3080 us/op 4.3460 us/op 0.76
mainnet_e217614 - capella processRandaoMixesReset 4.4190 us/op 7.5620 us/op 0.58
mainnet_e217614 - capella processHistoricalRootsUpdate 478.00 ns/op 431.00 ns/op 1.11
mainnet_e217614 - capella processParticipationFlagUpdates 1.4250 us/op 1.4720 us/op 0.97
mainnet_e217614 - capella afterProcessEpoch 316.30 ms/op 324.86 ms/op 0.97
phase0 processEpoch - mainnet_e58758 492.64 ms/op 467.16 ms/op 1.05
mainnet_e58758 - phase0 beforeProcessEpoch 113.24 ms/op 121.18 ms/op 0.93
mainnet_e58758 - phase0 processJustificationAndFinalization 16.359 us/op 16.160 us/op 1.01
mainnet_e58758 - phase0 processRewardsAndPenalties 56.818 ms/op 53.539 ms/op 1.06
mainnet_e58758 - phase0 processRegistryUpdates 11.300 us/op 10.390 us/op 1.09
mainnet_e58758 - phase0 processSlashings 639.00 ns/op 538.00 ns/op 1.19
mainnet_e58758 - phase0 processEth1DataReset 369.00 ns/op 376.00 ns/op 0.98
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.1470 ms/op 1.1608 ms/op 0.99
mainnet_e58758 - phase0 processSlashingsReset 2.7430 us/op 4.1090 us/op 0.67
mainnet_e58758 - phase0 processRandaoMixesReset 4.2410 us/op 4.0210 us/op 1.05
mainnet_e58758 - phase0 processHistoricalRootsUpdate 469.00 ns/op 465.00 ns/op 1.01
mainnet_e58758 - phase0 processParticipationRecordUpdates 5.1280 us/op 3.1960 us/op 1.60
mainnet_e58758 - phase0 afterProcessEpoch 97.957 ms/op 95.741 ms/op 1.02
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.4355 ms/op 1.4046 ms/op 1.02
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.5504 ms/op 1.5675 ms/op 0.99
altair processInactivityUpdates - 250000 normalcase 27.845 ms/op 22.633 ms/op 1.23
altair processInactivityUpdates - 250000 worstcase 31.537 ms/op 26.726 ms/op 1.18
phase0 processRegistryUpdates - 250000 normalcase 10.415 us/op 8.5330 us/op 1.22
phase0 processRegistryUpdates - 250000 badcase_full_deposits 394.90 us/op 392.11 us/op 1.01
phase0 processRegistryUpdates - 250000 worstcase 0.5 143.54 ms/op 122.18 ms/op 1.17
altair processRewardsAndPenalties - 250000 normalcase 61.927 ms/op 60.541 ms/op 1.02
altair processRewardsAndPenalties - 250000 worstcase 59.521 ms/op 56.345 ms/op 1.06
phase0 getAttestationDeltas - 250000 normalcase 10.399 ms/op 8.7505 ms/op 1.19
phase0 getAttestationDeltas - 250000 worstcase 9.9801 ms/op 9.6382 ms/op 1.04
phase0 processSlashings - 250000 worstcase 109.00 us/op 91.957 us/op 1.19
altair processSyncCommitteeUpdates - 250000 163.04 ms/op 156.41 ms/op 1.04
BeaconState.hashTreeRoot - No change 266.00 ns/op 279.00 ns/op 0.95
BeaconState.hashTreeRoot - 1 full validator 136.85 us/op 152.18 us/op 0.90
BeaconState.hashTreeRoot - 32 full validator 1.3845 ms/op 1.5033 ms/op 0.92
BeaconState.hashTreeRoot - 512 full validator 14.171 ms/op 18.899 ms/op 0.75
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 162.88 us/op 217.97 us/op 0.75
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 2.1131 ms/op 2.1629 ms/op 0.98
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 27.087 ms/op 28.830 ms/op 0.94
BeaconState.hashTreeRoot - 1 balances 136.89 us/op 122.81 us/op 1.11
BeaconState.hashTreeRoot - 32 balances 1.3213 ms/op 1.1012 ms/op 1.20
BeaconState.hashTreeRoot - 512 balances 15.337 ms/op 17.039 ms/op 0.90
BeaconState.hashTreeRoot - 250000 balances 236.02 ms/op 191.84 ms/op 1.23
aggregationBits - 2048 els - zipIndexesInBitList 20.536 us/op 17.567 us/op 1.17
byteArrayEquals 32 77.952 ns/op 74.156 ns/op 1.05
Buffer.compare 32 58.069 ns/op 55.489 ns/op 1.05
byteArrayEquals 1024 2.1324 us/op 1.9760 us/op 1.08
Buffer.compare 1024 75.544 ns/op 68.704 ns/op 1.10
byteArrayEquals 16384 33.872 us/op 32.149 us/op 1.05
Buffer.compare 16384 294.33 ns/op 269.65 ns/op 1.09
byteArrayEquals 123687377 257.84 ms/op 248.04 ms/op 1.04
Buffer.compare 123687377 7.0542 ms/op 8.2399 ms/op 0.86
byteArrayEquals 32 - diff last byte 75.429 ns/op 73.137 ns/op 1.03
Buffer.compare 32 - diff last byte 59.128 ns/op 57.264 ns/op 1.03
byteArrayEquals 1024 - diff last byte 2.1324 us/op 2.0942 us/op 1.02
Buffer.compare 1024 - diff last byte 74.425 ns/op 74.388 ns/op 1.00
byteArrayEquals 16384 - diff last byte 33.953 us/op 33.441 us/op 1.02
Buffer.compare 16384 - diff last byte 299.37 ns/op 262.95 ns/op 1.14
byteArrayEquals 123687377 - diff last byte 266.88 ms/op 247.00 ms/op 1.08
Buffer.compare 123687377 - diff last byte 7.4836 ms/op 7.2223 ms/op 1.04
byteArrayEquals 32 - random bytes 6.3830 ns/op 5.5930 ns/op 1.14
Buffer.compare 32 - random bytes 66.524 ns/op 60.883 ns/op 1.09
byteArrayEquals 1024 - random bytes 6.2660 ns/op 5.1950 ns/op 1.21
Buffer.compare 1024 - random bytes 65.349 ns/op 59.228 ns/op 1.10
byteArrayEquals 16384 - random bytes 5.8680 ns/op 5.3840 ns/op 1.09
Buffer.compare 16384 - random bytes 64.591 ns/op 60.049 ns/op 1.08
byteArrayEquals 123687377 - random bytes 9.7400 ns/op 8.5500 ns/op 1.14
Buffer.compare 123687377 - random bytes 77.710 ns/op 63.820 ns/op 1.22
regular array get 100000 times 48.410 us/op 44.849 us/op 1.08
wrappedArray get 100000 times 48.189 us/op 44.861 us/op 1.07
arrayWithProxy get 100000 times 17.936 ms/op 14.251 ms/op 1.26
ssz.Root.equals 62.513 ns/op 54.040 ns/op 1.16
byteArrayEquals 59.716 ns/op 53.087 ns/op 1.12
Buffer.compare 13.250 ns/op 11.987 ns/op 1.11
shuffle list - 16384 els 7.4430 ms/op 7.0339 ms/op 1.06
shuffle list - 250000 els 112.08 ms/op 103.54 ms/op 1.08
processSlot - 1 slots 19.868 us/op 17.249 us/op 1.15
processSlot - 32 slots 3.5460 ms/op 3.0352 ms/op 1.17
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 58.315 ms/op 55.220 ms/op 1.06
getCommitteeAssignments - req 1 vs - 250000 vc 2.7346 ms/op 2.4843 ms/op 1.10
getCommitteeAssignments - req 100 vs - 250000 vc 4.0419 ms/op 3.6614 ms/op 1.10
getCommitteeAssignments - req 1000 vs - 250000 vc 4.4542 ms/op 4.0440 ms/op 1.10
findModifiedValidators - 10000 modified validators 579.24 ms/op 523.62 ms/op 1.11
findModifiedValidators - 1000 modified validators 457.87 ms/op 430.54 ms/op 1.06
findModifiedValidators - 100 modified validators 425.96 ms/op 380.59 ms/op 1.12
findModifiedValidators - 10 modified validators 444.44 ms/op 394.07 ms/op 1.13
findModifiedValidators - 1 modified validators 427.82 ms/op 431.32 ms/op 0.99
findModifiedValidators - no difference 450.66 ms/op 425.19 ms/op 1.06
compare ViewDUs 4.4671 s/op 4.3265 s/op 1.03
compare each validator Uint8Array 1.7745 s/op 1.8364 s/op 0.97
compare ViewDU to Uint8Array 1.1985 s/op 1.1131 s/op 1.08
migrate state 1000000 validators, 24 modified, 0 new 773.00 ms/op 781.60 ms/op 0.99
migrate state 1000000 validators, 1700 modified, 1000 new 1.1608 s/op 1.0800 s/op 1.07
migrate state 1000000 validators, 3400 modified, 2000 new 1.5211 s/op 1.3188 s/op 1.15
migrate state 1500000 validators, 24 modified, 0 new 767.15 ms/op 796.33 ms/op 0.96
migrate state 1500000 validators, 1700 modified, 1000 new 1.1308 s/op 1.0936 s/op 1.03
migrate state 1500000 validators, 3400 modified, 2000 new 1.3689 s/op 1.3197 s/op 1.04
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.6500 ns/op 4.4000 ns/op 1.06
state getBlockRootAtSlot - 250000 vs - 7PWei 719.56 ns/op 730.74 ns/op 0.98
computeProposers - vc 250000 10.179 ms/op 9.1791 ms/op 1.11
computeEpochShuffling - vc 250000 110.01 ms/op 99.063 ms/op 1.11
getNextSyncCommittee - vc 250000 166.95 ms/op 157.65 ms/op 1.06
computeSigningRoot for AttestationData 30.802 us/op 26.756 us/op 1.15
hash AttestationData serialized data then Buffer.toString(base64) 2.4435 us/op 2.2539 us/op 1.08
toHexString serialized data 1.2537 us/op 1.0456 us/op 1.20
Buffer.toString(base64) 251.82 ns/op 211.17 ns/op 1.19

by benchmarkbot/action

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.

link to video?

@wemeetagain wemeetagain merged commit b082a48 into unstable Jan 16, 2024
13 of 15 checks passed
@wemeetagain wemeetagain deleted the nflaig/cleanup-forEach branch January 16, 2024 15:22
@nflaig
Copy link
Member Author

nflaig commented Jan 16, 2024

link to video?

The video was not primarily about for loop performance, just comment in the video. I looked up a few benchmarks yesterday and for...of seems to be slightly better than forEach.

Just now, I looked up a few more benchmarks and the results seem mixed though, I also just noticed this was discussed already #1845 (comment).

But yeah primary reason is code consistency as we wanna avoid forEach, the points brought up by Lion in #1845 (comment) are more relevant than the performance part of it.

If we wanna min-max the performance would likely have to use a regular for loop (based on all benchmarks) but that makes the code less readable in most cases and likely not worth it.

ensi321 pushed a commit to ensi321/lodestar that referenced this pull request Jan 22, 2024
@wemeetagain
Copy link
Member

🎉 This PR is included in v1.15.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.

2 participants