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: drop start stop pattern from Network where possible #5588

Merged
merged 2 commits into from
May 31, 2023

Conversation

dapplion
Copy link
Contributor

Motivation

Lodestar does not support start stop syntax in general. It's unnecessary for downstream classes to expose such behavior

Description

upstream dependencies have the start stop pattern baked in and is not worth it to change (libp2p itself, gossip, reqresp).

This PR just changes local classes which don't really need the start stop pattern

Closes #4501

@dapplion dapplion requested a review from a team as a code owner May 30, 2023 16:37
@github-actions
Copy link
Contributor

github-actions bot commented May 30, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 66ce920 Previous: 399687b Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 945.83 us/op 860.71 us/op 1.10
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 58.628 us/op 48.338 us/op 1.21
BLS verify - blst-native 1.2402 ms/op 1.2123 ms/op 1.02
BLS verifyMultipleSignatures 3 - blst-native 2.6478 ms/op 2.4695 ms/op 1.07
BLS verifyMultipleSignatures 8 - blst-native 5.6431 ms/op 5.4467 ms/op 1.04
BLS verifyMultipleSignatures 32 - blst-native 20.112 ms/op 20.275 ms/op 0.99
BLS aggregatePubkeys 32 - blst-native 26.948 us/op 26.852 us/op 1.00
BLS aggregatePubkeys 128 - blst-native 104.14 us/op 103.83 us/op 1.00
getAttestationsForBlock 70.415 ms/op 59.766 ms/op 1.18
isKnown best case - 1 super set check 268.00 ns/op 263.00 ns/op 1.02
isKnown normal case - 2 super set checks 274.00 ns/op 256.00 ns/op 1.07
isKnown worse case - 16 super set checks 322.00 ns/op 260.00 ns/op 1.24
CheckpointStateCache - add get delete 6.0250 us/op 5.7280 us/op 1.05
validate gossip signedAggregateAndProof - struct 2.9046 ms/op 2.7881 ms/op 1.04
validate gossip attestation - struct 1.3620 ms/op 1.3380 ms/op 1.02
pickEth1Vote - no votes 1.4164 ms/op 1.3436 ms/op 1.05
pickEth1Vote - max votes 12.267 ms/op 10.309 ms/op 1.19
pickEth1Vote - Eth1Data hashTreeRoot value x2048 10.158 ms/op 8.9393 ms/op 1.14
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 23.539 ms/op 16.520 ms/op 1.42
pickEth1Vote - Eth1Data fastSerialize value x2048 866.18 us/op 778.43 us/op 1.11
pickEth1Vote - Eth1Data fastSerialize tree x2048 10.708 ms/op 6.9218 ms/op 1.55
bytes32 toHexString 808.00 ns/op 640.00 ns/op 1.26
bytes32 Buffer.toString(hex) 496.00 ns/op 437.00 ns/op 1.14
bytes32 Buffer.toString(hex) from Uint8Array 744.00 ns/op 642.00 ns/op 1.16
bytes32 Buffer.toString(hex) + 0x 502.00 ns/op 409.00 ns/op 1.23
Object access 1 prop 0.20000 ns/op 0.19000 ns/op 1.05
Map access 1 prop 0.19400 ns/op 0.16300 ns/op 1.19
Object get x1000 8.5360 ns/op 6.5740 ns/op 1.30
Map get x1000 0.80300 ns/op 0.63700 ns/op 1.26
Object set x1000 89.264 ns/op 56.006 ns/op 1.59
Map set x1000 69.382 ns/op 48.717 ns/op 1.42
Return object 10000 times 0.27010 ns/op 0.24430 ns/op 1.11
Throw Error 10000 times 4.8449 us/op 4.3462 us/op 1.11
fastMsgIdFn sha256 / 200 bytes 4.0200 us/op 3.4720 us/op 1.16
fastMsgIdFn h32 xxhash / 200 bytes 403.00 ns/op 303.00 ns/op 1.33
fastMsgIdFn h64 xxhash / 200 bytes 556.00 ns/op 450.00 ns/op 1.24
fastMsgIdFn sha256 / 1000 bytes 13.062 us/op 11.743 us/op 1.11
fastMsgIdFn h32 xxhash / 1000 bytes 522.00 ns/op 441.00 ns/op 1.18
fastMsgIdFn h64 xxhash / 1000 bytes 650.00 ns/op 505.00 ns/op 1.29
fastMsgIdFn sha256 / 10000 bytes 110.14 us/op 105.10 us/op 1.05
fastMsgIdFn h32 xxhash / 10000 bytes 2.5580 us/op 1.9980 us/op 1.28
fastMsgIdFn h64 xxhash / 10000 bytes 2.0740 us/op 1.4820 us/op 1.40
enrSubnets - fastDeserialize 64 bits 2.3220 us/op 1.5190 us/op 1.53
enrSubnets - ssz BitVector 64 bits 977.00 ns/op 626.00 ns/op 1.56
enrSubnets - fastDeserialize 4 bits 263.00 ns/op 207.00 ns/op 1.27
enrSubnets - ssz BitVector 4 bits 828.00 ns/op 583.00 ns/op 1.42
prioritizePeers score -10:0 att 32-0.1 sync 2-0 129.30 us/op 117.53 us/op 1.10
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 182.96 us/op 161.00 us/op 1.14
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 240.83 us/op 192.20 us/op 1.25
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 535.37 us/op 351.90 us/op 1.52
prioritizePeers score 0:0 att 64-1 sync 4-1 617.25 us/op 435.52 us/op 1.42
array of 16000 items push then shift 1.8024 us/op 1.6925 us/op 1.06
LinkedList of 16000 items push then shift 9.8540 ns/op 9.1800 ns/op 1.07
array of 16000 items push then pop 128.96 ns/op 113.04 ns/op 1.14
LinkedList of 16000 items push then pop 10.220 ns/op 8.9900 ns/op 1.14
array of 24000 items push then shift 2.8285 us/op 2.3961 us/op 1.18
LinkedList of 24000 items push then shift 12.356 ns/op 9.1940 ns/op 1.34
array of 24000 items push then pop 105.01 ns/op 95.426 ns/op 1.10
LinkedList of 24000 items push then pop 10.383 ns/op 9.7640 ns/op 1.06
intersect bitArray bitLen 8 15.763 ns/op 15.831 ns/op 1.00
intersect array and set length 8 133.54 ns/op 114.59 ns/op 1.17
intersect bitArray bitLen 128 48.269 ns/op 47.772 ns/op 1.01
intersect array and set length 128 1.5442 us/op 1.3730 us/op 1.12
Buffer.concat 32 items 3.9370 us/op 3.2360 us/op 1.22
Uint8Array.set 32 items 3.0930 us/op 2.9520 us/op 1.05
transfer serialized Status (84 B) 2.2100 us/op 2.3410 us/op 0.94
copy serialized Status (84 B) 1.8630 us/op 2.0880 us/op 0.89
transfer serialized SignedVoluntaryExit (112 B) 2.3900 us/op 2.5410 us/op 0.94
copy serialized SignedVoluntaryExit (112 B) 2.0480 us/op 2.1320 us/op 0.96
transfer serialized ProposerSlashing (416 B) 2.8610 us/op 2.5580 us/op 1.12
copy serialized ProposerSlashing (416 B) 3.3010 us/op 2.4120 us/op 1.37
transfer serialized Attestation (485 B) 3.0950 us/op 2.5130 us/op 1.23
copy serialized Attestation (485 B) 2.9870 us/op 2.3840 us/op 1.25
transfer serialized AttesterSlashing (33232 B) 3.7680 us/op 3.1480 us/op 1.20
copy serialized AttesterSlashing (33232 B) 14.973 us/op 8.8340 us/op 1.69
transfer serialized Small SignedBeaconBlock (128000 B) 5.8370 us/op 3.5380 us/op 1.65
copy serialized Small SignedBeaconBlock (128000 B) 38.444 us/op 26.559 us/op 1.45
transfer serialized Avg SignedBeaconBlock (200000 B) 6.6020 us/op 4.1420 us/op 1.59
copy serialized Avg SignedBeaconBlock (200000 B) 46.496 us/op 57.717 us/op 0.81
transfer serialized BlobsSidecar (524380 B) 4.3640 us/op 4.0460 us/op 1.08
copy serialized BlobsSidecar (524380 B) 172.99 us/op 172.06 us/op 1.01
transfer serialized Big SignedBeaconBlock (1000000 B) 5.8610 us/op 4.2850 us/op 1.37
copy serialized Big SignedBeaconBlock (1000000 B) 512.75 us/op 378.69 us/op 1.35
pass gossip attestations to forkchoice per slot 2.7863 ms/op 2.6032 ms/op 1.07
computeDeltas 4.6937 ms/op 3.4229 ms/op 1.37
computeProposerBoostScoreFromBalances 2.1766 ms/op 1.8961 ms/op 1.15
altair processAttestation - 250000 vs - 7PWei normalcase 4.5221 ms/op 3.5440 ms/op 1.28
altair processAttestation - 250000 vs - 7PWei worstcase 6.7496 ms/op 5.5572 ms/op 1.21
altair processAttestation - setStatus - 1/6 committees join 156.32 us/op 159.26 us/op 0.98
altair processAttestation - setStatus - 1/3 committees join 337.73 us/op 299.92 us/op 1.13
altair processAttestation - setStatus - 1/2 committees join 444.62 us/op 393.52 us/op 1.13
altair processAttestation - setStatus - 2/3 committees join 526.20 us/op 506.86 us/op 1.04
altair processAttestation - setStatus - 4/5 committees join 866.45 us/op 747.81 us/op 1.16
altair processAttestation - setStatus - 100% committees join 866.40 us/op 835.95 us/op 1.04
altair processBlock - 250000 vs - 7PWei normalcase 25.091 ms/op 23.799 ms/op 1.05
altair processBlock - 250000 vs - 7PWei normalcase hashState 34.673 ms/op 31.106 ms/op 1.11
altair processBlock - 250000 vs - 7PWei worstcase 80.793 ms/op 59.090 ms/op 1.37
altair processBlock - 250000 vs - 7PWei worstcase hashState 90.329 ms/op 82.332 ms/op 1.10
phase0 processBlock - 250000 vs - 7PWei normalcase 2.9920 ms/op 2.9566 ms/op 1.01
phase0 processBlock - 250000 vs - 7PWei worstcase 39.378 ms/op 35.613 ms/op 1.11
altair processEth1Data - 250000 vs - 7PWei normalcase 737.73 us/op 647.67 us/op 1.14
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 16.768 us/op 14.154 us/op 1.18
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 33.645 us/op 38.099 us/op 0.88
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 19.805 us/op 18.377 us/op 1.08
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 16.935 us/op 15.305 us/op 1.11
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 134.55 us/op 122.33 us/op 1.10
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 833.26 us/op 816.82 us/op 1.02
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.3250 ms/op 985.02 us/op 1.35
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.1539 ms/op 1.0953 ms/op 1.05
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 4.6258 ms/op 3.5426 ms/op 1.31
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 2.3668 ms/op 2.1102 ms/op 1.12
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 8.9857 ms/op 5.8892 ms/op 1.53
Tree 40 250000 create 1.0113 s/op 633.66 ms/op 1.60
Tree 40 250000 get(125000) 226.24 ns/op 228.94 ns/op 0.99
Tree 40 250000 set(125000) 1.8671 us/op 1.4460 us/op 1.29
Tree 40 250000 toArray() 26.000 ms/op 26.678 ms/op 0.97
Tree 40 250000 iterate all - toArray() + loop 24.285 ms/op 24.340 ms/op 1.00
Tree 40 250000 iterate all - get(i) 89.357 ms/op 81.723 ms/op 1.09
MutableVector 250000 create 18.116 ms/op 13.460 ms/op 1.35
MutableVector 250000 get(125000) 7.6210 ns/op 6.7580 ns/op 1.13
MutableVector 250000 set(125000) 612.39 ns/op 423.88 ns/op 1.44
MutableVector 250000 toArray() 3.8943 ms/op 3.8941 ms/op 1.00
MutableVector 250000 iterate all - toArray() + loop 3.9479 ms/op 4.0711 ms/op 0.97
MutableVector 250000 iterate all - get(i) 1.6121 ms/op 1.5968 ms/op 1.01
Array 250000 create 4.4224 ms/op 3.5744 ms/op 1.24
Array 250000 clone - spread 1.4221 ms/op 1.2505 ms/op 1.14
Array 250000 get(125000) 0.68900 ns/op 0.69000 ns/op 1.00
Array 250000 set(125000) 0.80400 ns/op 0.71500 ns/op 1.12
Array 250000 iterate all - loop 88.290 us/op 94.393 us/op 0.94
effectiveBalanceIncrements clone Uint8Array 300000 61.559 us/op 53.689 us/op 1.15
effectiveBalanceIncrements clone MutableVector 300000 429.00 ns/op 409.00 ns/op 1.05
effectiveBalanceIncrements rw all Uint8Array 300000 187.49 us/op 180.46 us/op 1.04
effectiveBalanceIncrements rw all MutableVector 300000 138.39 ms/op 115.76 ms/op 1.20
phase0 afterProcessEpoch - 250000 vs - 7PWei 133.72 ms/op 125.17 ms/op 1.07
phase0 beforeProcessEpoch - 250000 vs - 7PWei 51.084 ms/op 42.886 ms/op 1.19
altair processEpoch - mainnet_e81889 515.14 ms/op 347.65 ms/op 1.48
mainnet_e81889 - altair beforeProcessEpoch 127.74 ms/op 75.386 ms/op 1.69
mainnet_e81889 - altair processJustificationAndFinalization 36.056 us/op 21.167 us/op 1.70
mainnet_e81889 - altair processInactivityUpdates 13.176 ms/op 6.2487 ms/op 2.11
mainnet_e81889 - altair processRewardsAndPenalties 125.92 ms/op 70.225 ms/op 1.79
mainnet_e81889 - altair processRegistryUpdates 5.0120 us/op 3.3320 us/op 1.50
mainnet_e81889 - altair processSlashings 1.4790 us/op 511.00 ns/op 2.89
mainnet_e81889 - altair processEth1DataReset 1.4040 us/op 637.00 ns/op 2.20
mainnet_e81889 - altair processEffectiveBalanceUpdates 7.7410 ms/op 1.3412 ms/op 5.77
mainnet_e81889 - altair processSlashingsReset 10.709 us/op 4.0070 us/op 2.67
mainnet_e81889 - altair processRandaoMixesReset 9.0940 us/op 4.9560 us/op 1.83
mainnet_e81889 - altair processHistoricalRootsUpdate 1.6020 us/op 2.0420 us/op 0.78
mainnet_e81889 - altair processParticipationFlagUpdates 6.4140 us/op 2.3940 us/op 2.68
mainnet_e81889 - altair processSyncCommitteeUpdates 1.2510 us/op 630.00 ns/op 1.99
mainnet_e81889 - altair afterProcessEpoch 131.10 ms/op 131.34 ms/op 1.00
phase0 processEpoch - mainnet_e58758 420.62 ms/op 389.85 ms/op 1.08
mainnet_e58758 - phase0 beforeProcessEpoch 214.30 ms/op 149.76 ms/op 1.43
mainnet_e58758 - phase0 processJustificationAndFinalization 34.916 us/op 22.758 us/op 1.53
mainnet_e58758 - phase0 processRewardsAndPenalties 77.388 ms/op 60.921 ms/op 1.27
mainnet_e58758 - phase0 processRegistryUpdates 19.624 us/op 11.505 us/op 1.71
mainnet_e58758 - phase0 processSlashings 1.2780 us/op 850.00 ns/op 1.50
mainnet_e58758 - phase0 processEth1DataReset 1.1710 us/op 853.00 ns/op 1.37
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 2.4255 ms/op 1.1904 ms/op 2.04
mainnet_e58758 - phase0 processSlashingsReset 7.1900 us/op 7.0990 us/op 1.01
mainnet_e58758 - phase0 processRandaoMixesReset 11.591 us/op 6.8520 us/op 1.69
mainnet_e58758 - phase0 processHistoricalRootsUpdate 2.2340 us/op 745.00 ns/op 3.00
mainnet_e58758 - phase0 processParticipationRecordUpdates 12.596 us/op 5.1200 us/op 2.46
mainnet_e58758 - phase0 afterProcessEpoch 115.86 ms/op 107.75 ms/op 1.08
phase0 processEffectiveBalanceUpdates - 250000 normalcase 2.0403 ms/op 1.6193 ms/op 1.26
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 2.0841 ms/op 1.8427 ms/op 1.13
altair processInactivityUpdates - 250000 normalcase 30.369 ms/op 29.363 ms/op 1.03
altair processInactivityUpdates - 250000 worstcase 28.631 ms/op 28.530 ms/op 1.00
phase0 processRegistryUpdates - 250000 normalcase 14.571 us/op 14.294 us/op 1.02
phase0 processRegistryUpdates - 250000 badcase_full_deposits 333.78 us/op 371.62 us/op 0.90
phase0 processRegistryUpdates - 250000 worstcase 0.5 219.95 ms/op 150.02 ms/op 1.47
altair processRewardsAndPenalties - 250000 normalcase 86.371 ms/op 73.999 ms/op 1.17
altair processRewardsAndPenalties - 250000 worstcase 82.894 ms/op 74.144 ms/op 1.12
phase0 getAttestationDeltas - 250000 normalcase 11.565 ms/op 8.7093 ms/op 1.33
phase0 getAttestationDeltas - 250000 worstcase 11.754 ms/op 8.9335 ms/op 1.32
phase0 processSlashings - 250000 worstcase 4.6911 ms/op 4.4874 ms/op 1.05
altair processSyncCommitteeUpdates - 250000 195.32 ms/op 194.63 ms/op 1.00
BeaconState.hashTreeRoot - No change 458.00 ns/op 283.00 ns/op 1.62
BeaconState.hashTreeRoot - 1 full validator 68.713 us/op 55.944 us/op 1.23
BeaconState.hashTreeRoot - 32 full validator 656.31 us/op 572.44 us/op 1.15
BeaconState.hashTreeRoot - 512 full validator 7.1804 ms/op 5.9408 ms/op 1.21
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 74.773 us/op 71.003 us/op 1.05
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.1139 ms/op 1.0197 ms/op 1.09
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 15.944 ms/op 13.358 ms/op 1.19
BeaconState.hashTreeRoot - 1 balances 57.501 us/op 58.140 us/op 0.99
BeaconState.hashTreeRoot - 32 balances 494.68 us/op 491.56 us/op 1.01
BeaconState.hashTreeRoot - 512 balances 5.8111 ms/op 5.0665 ms/op 1.15
BeaconState.hashTreeRoot - 250000 balances 80.987 ms/op 78.218 ms/op 1.04
aggregationBits - 2048 els - zipIndexesInBitList 42.231 us/op 24.151 us/op 1.75
regular array get 100000 times 43.706 us/op 36.057 us/op 1.21
wrappedArray get 100000 times 50.561 us/op 45.417 us/op 1.11
arrayWithProxy get 100000 times 17.208 ms/op 17.021 ms/op 1.01
ssz.Root.equals 691.00 ns/op 620.00 ns/op 1.11
byteArrayEquals 664.00 ns/op 606.00 ns/op 1.10
shuffle list - 16384 els 7.8377 ms/op 7.5231 ms/op 1.04
shuffle list - 250000 els 112.32 ms/op 112.28 ms/op 1.00
processSlot - 1 slots 12.571 us/op 9.7710 us/op 1.29
processSlot - 32 slots 1.7017 ms/op 1.5029 ms/op 1.13
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 42.636 ms/op 36.231 ms/op 1.18
getCommitteeAssignments - req 1 vs - 250000 vc 3.6525 ms/op 2.8701 ms/op 1.27
getCommitteeAssignments - req 100 vs - 250000 vc 5.1063 ms/op 4.1221 ms/op 1.24
getCommitteeAssignments - req 1000 vs - 250000 vc 5.3376 ms/op 4.4717 ms/op 1.19
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 5.5700 ns/op 4.6800 ns/op 1.19
state getBlockRootAtSlot - 250000 vs - 7PWei 895.91 ns/op 795.29 ns/op 1.13
computeProposers - vc 250000 12.976 ms/op 10.153 ms/op 1.28
computeEpochShuffling - vc 250000 112.17 ms/op 106.06 ms/op 1.06
getNextSyncCommittee - vc 250000 216.76 ms/op 171.22 ms/op 1.27
computeSigningRoot for AttestationData 16.127 us/op 13.088 us/op 1.23
hash AttestationData serialized data then Buffer.toString(base64) 2.9162 us/op 2.4388 us/op 1.20
toHexString serialized data 1.7668 us/op 1.1033 us/op 1.60
Buffer.toString(base64) 439.87 ns/op 309.35 ns/op 1.42

by benchmarkbot/action

@dapplion dapplion changed the title Drop start stop pattern from Network where possible refactor: drop start stop pattern from Network where possible May 31, 2023
@wemeetagain wemeetagain merged commit 7fc4cfd into unstable May 31, 2023
10 of 11 checks passed
@wemeetagain wemeetagain deleted the dapplion/network-close branch May 31, 2023 18:55
@wemeetagain
Copy link
Member

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

Make network classes startable once
2 participants