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

Restrict import destructuring for some modules #5203

Merged
merged 2 commits into from
Feb 28, 2023

Conversation

nflaig
Copy link
Member

@nflaig nflaig commented Feb 24, 2023

Motivation

Closes #5201

Description

Adds eslint rule to restrict import destructuring for some modules ("node:fs", "node:os", "node:path"). Further modules could be added but those are the ones where I saw the highest inconsistency on how the imports are done and also these use really ambiguous function names.

Also refactored the eslint rule for restricted node module imports.

cc @nazarhussain

@nflaig nflaig requested a review from a team as a code owner February 24, 2023 14:59
@github-actions
Copy link
Contributor

github-actions bot commented Feb 24, 2023

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: a0b7aea Previous: 6429685 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 797.95 us/op 501.82 us/op 1.59
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 51.016 us/op 47.651 us/op 1.07
BLS verify - blst-native 1.2810 ms/op 1.2347 ms/op 1.04
BLS verifyMultipleSignatures 3 - blst-native 2.5556 ms/op 2.4597 ms/op 1.04
BLS verifyMultipleSignatures 8 - blst-native 5.4704 ms/op 5.2457 ms/op 1.04
BLS verifyMultipleSignatures 32 - blst-native 20.124 ms/op 19.187 ms/op 1.05
BLS aggregatePubkeys 32 - blst-native 26.719 us/op 25.852 us/op 1.03
BLS aggregatePubkeys 128 - blst-native 102.60 us/op 99.981 us/op 1.03
getAttestationsForBlock 69.461 ms/op 52.230 ms/op 1.33
isKnown best case - 1 super set check 312.00 ns/op 266.00 ns/op 1.17
isKnown normal case - 2 super set checks 287.00 ns/op 261.00 ns/op 1.10
isKnown worse case - 16 super set checks 289.00 ns/op 255.00 ns/op 1.13
CheckpointStateCache - add get delete 5.9310 us/op 5.2070 us/op 1.14
validate gossip signedAggregateAndProof - struct 2.8604 ms/op 2.7806 ms/op 1.03
validate gossip attestation - struct 1.3396 ms/op 1.3248 ms/op 1.01
pickEth1Vote - no votes 1.3860 ms/op 1.2324 ms/op 1.12
pickEth1Vote - max votes 12.969 ms/op 10.539 ms/op 1.23
pickEth1Vote - Eth1Data hashTreeRoot value x2048 10.093 ms/op 8.6177 ms/op 1.17
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 17.732 ms/op 14.883 ms/op 1.19
pickEth1Vote - Eth1Data fastSerialize value x2048 825.45 us/op 637.53 us/op 1.29
pickEth1Vote - Eth1Data fastSerialize tree x2048 9.2610 ms/op 8.0863 ms/op 1.15
bytes32 toHexString 722.00 ns/op 518.00 ns/op 1.39
bytes32 Buffer.toString(hex) 428.00 ns/op 346.00 ns/op 1.24
bytes32 Buffer.toString(hex) from Uint8Array 630.00 ns/op 556.00 ns/op 1.13
bytes32 Buffer.toString(hex) + 0x 434.00 ns/op 337.00 ns/op 1.29
Object access 1 prop 0.20000 ns/op 0.17200 ns/op 1.16
Map access 1 prop 0.17200 ns/op 0.15800 ns/op 1.09
Object get x1000 6.8580 ns/op 6.5440 ns/op 1.05
Map get x1000 0.67700 ns/op 0.63800 ns/op 1.06
Object set x1000 66.017 ns/op 53.499 ns/op 1.23
Map set x1000 53.613 ns/op 43.388 ns/op 1.24
Return object 10000 times 0.25010 ns/op 0.23350 ns/op 1.07
Throw Error 10000 times 4.4960 us/op 4.0574 us/op 1.11
fastMsgIdFn sha256 / 200 bytes 3.6670 us/op 3.4370 us/op 1.07
fastMsgIdFn h32 xxhash / 200 bytes 321.00 ns/op 271.00 ns/op 1.18
fastMsgIdFn h64 xxhash / 200 bytes 465.00 ns/op 382.00 ns/op 1.22
fastMsgIdFn sha256 / 1000 bytes 12.213 us/op 11.500 us/op 1.06
fastMsgIdFn h32 xxhash / 1000 bytes 467.00 ns/op 401.00 ns/op 1.16
fastMsgIdFn h64 xxhash / 1000 bytes 557.00 ns/op 453.00 ns/op 1.23
fastMsgIdFn sha256 / 10000 bytes 107.17 us/op 103.31 us/op 1.04
fastMsgIdFn h32 xxhash / 10000 bytes 2.0970 us/op 1.9190 us/op 1.09
fastMsgIdFn h64 xxhash / 10000 bytes 1.5140 us/op 1.3700 us/op 1.11
enrSubnets - fastDeserialize 64 bits 1.8370 us/op 1.2790 us/op 1.44
enrSubnets - ssz BitVector 64 bits 639.00 ns/op 487.00 ns/op 1.31
enrSubnets - fastDeserialize 4 bits 209.00 ns/op 165.00 ns/op 1.27
enrSubnets - ssz BitVector 4 bits 611.00 ns/op 484.00 ns/op 1.26
prioritizePeers score -10:0 att 32-0.1 sync 2-0 113.32 us/op 94.454 us/op 1.20
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 165.36 us/op 129.13 us/op 1.28
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 212.74 us/op 159.38 us/op 1.33
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 381.56 us/op 298.36 us/op 1.28
prioritizePeers score 0:0 att 64-1 sync 4-1 455.80 us/op 355.85 us/op 1.28
array of 16000 items push then shift 1.7389 us/op 1.6224 us/op 1.07
LinkedList of 16000 items push then shift 9.6840 ns/op 8.6630 ns/op 1.12
array of 16000 items push then pop 114.37 ns/op 91.372 ns/op 1.25
LinkedList of 16000 items push then pop 9.5020 ns/op 8.5070 ns/op 1.12
array of 24000 items push then shift 2.4657 us/op 2.3615 us/op 1.04
LinkedList of 24000 items push then shift 10.291 ns/op 8.7140 ns/op 1.18
array of 24000 items push then pop 96.865 ns/op 71.467 ns/op 1.36
LinkedList of 24000 items push then pop 9.3190 ns/op 8.4250 ns/op 1.11
intersect bitArray bitLen 8 14.029 ns/op 13.129 ns/op 1.07
intersect array and set length 8 100.53 ns/op 74.890 ns/op 1.34
intersect bitArray bitLen 128 47.207 ns/op 43.862 ns/op 1.08
intersect array and set length 128 1.2474 us/op 1.0088 us/op 1.24
Buffer.concat 32 items 2.8970 us/op 2.5570 us/op 1.13
Uint8Array.set 32 items 2.5270 us/op 2.9280 us/op 0.86
pass gossip attestations to forkchoice per slot 2.5056 ms/op 2.2924 ms/op 1.09
computeDeltas 3.1311 ms/op 3.1269 ms/op 1.00
computeProposerBoostScoreFromBalances 1.8410 ms/op 1.7704 ms/op 1.04
altair processAttestation - 250000 vs - 7PWei normalcase 3.6030 ms/op 2.1404 ms/op 1.68
altair processAttestation - 250000 vs - 7PWei worstcase 5.2980 ms/op 3.6171 ms/op 1.46
altair processAttestation - setStatus - 1/6 committees join 147.71 us/op 141.64 us/op 1.04
altair processAttestation - setStatus - 1/3 committees join 304.74 us/op 270.86 us/op 1.13
altair processAttestation - setStatus - 1/2 committees join 389.80 us/op 383.23 us/op 1.02
altair processAttestation - setStatus - 2/3 committees join 483.23 us/op 471.23 us/op 1.03
altair processAttestation - setStatus - 4/5 committees join 686.09 us/op 656.46 us/op 1.05
altair processAttestation - setStatus - 100% committees join 818.10 us/op 757.31 us/op 1.08
altair processBlock - 250000 vs - 7PWei normalcase 21.328 ms/op 18.627 ms/op 1.15
altair processBlock - 250000 vs - 7PWei normalcase hashState 32.617 ms/op 24.894 ms/op 1.31
altair processBlock - 250000 vs - 7PWei worstcase 54.909 ms/op 49.819 ms/op 1.10
altair processBlock - 250000 vs - 7PWei worstcase hashState 81.250 ms/op 70.850 ms/op 1.15
phase0 processBlock - 250000 vs - 7PWei normalcase 2.9442 ms/op 2.0462 ms/op 1.44
phase0 processBlock - 250000 vs - 7PWei worstcase 33.834 ms/op 28.808 ms/op 1.17
altair processEth1Data - 250000 vs - 7PWei normalcase 643.56 us/op 518.76 us/op 1.24
vc - 250000 eb 1 eth1 1 we 0 wn 0 - smpl 15 10.085 us/op 7.7560 us/op 1.30
vc - 250000 eb 0.95 eth1 0.1 we 0.05 wn 0 - smpl 219 34.553 us/op 23.546 us/op 1.47
vc - 250000 eb 0.95 eth1 0.3 we 0.05 wn 0 - smpl 42 13.922 us/op 8.7400 us/op 1.59
vc - 250000 eb 0.95 eth1 0.7 we 0.05 wn 0 - smpl 18 10.669 us/op 7.3930 us/op 1.44
vc - 250000 eb 0.1 eth1 0.1 we 0 wn 0 - smpl 1020 129.68 us/op 87.102 us/op 1.49
vc - 250000 eb 0.03 eth1 0.03 we 0 wn 0 - smpl 11777 825.56 us/op 642.39 us/op 1.29
vc - 250000 eb 0.01 eth1 0.01 we 0 wn 0 - smpl 16384 934.01 us/op 938.05 us/op 1.00
vc - 250000 eb 0 eth1 0 we 0 wn 0 - smpl 16384 953.48 us/op 900.78 us/op 1.06
vc - 250000 eb 0 eth1 0 we 0 wn 0 nocache - smpl 16384 2.8185 ms/op 2.2853 ms/op 1.23
vc - 250000 eb 0 eth1 1 we 0 wn 0 - smpl 16384 1.5268 ms/op 1.5872 ms/op 0.96
vc - 250000 eb 0 eth1 1 we 0 wn 0 nocache - smpl 16384 4.5275 ms/op 3.8638 ms/op 1.17
Tree 40 250000 create 580.79 ms/op 320.21 ms/op 1.81
Tree 40 250000 get(125000) 204.57 ns/op 190.51 ns/op 1.07
Tree 40 250000 set(125000) 1.2356 us/op 974.91 ns/op 1.27
Tree 40 250000 toArray() 24.920 ms/op 18.697 ms/op 1.33
Tree 40 250000 iterate all - toArray() + loop 25.419 ms/op 17.977 ms/op 1.41
Tree 40 250000 iterate all - get(i) 79.812 ms/op 69.036 ms/op 1.16
MutableVector 250000 create 13.190 ms/op 11.374 ms/op 1.16
MutableVector 250000 get(125000) 6.8620 ns/op 6.4330 ns/op 1.07
MutableVector 250000 set(125000) 299.05 ns/op 258.63 ns/op 1.16
MutableVector 250000 toArray() 4.3726 ms/op 3.1389 ms/op 1.39
MutableVector 250000 iterate all - toArray() + loop 4.4896 ms/op 3.1263 ms/op 1.44
MutableVector 250000 iterate all - get(i) 1.6035 ms/op 1.5051 ms/op 1.07
Array 250000 create 4.2936 ms/op 2.7506 ms/op 1.56
Array 250000 clone - spread 2.0951 ms/op 1.1613 ms/op 1.80
Array 250000 get(125000) 1.4930 ns/op 0.56700 ns/op 2.63
Array 250000 set(125000) 1.7700 ns/op 0.64900 ns/op 2.73
Array 250000 iterate all - loop 115.84 us/op 106.61 us/op 1.09
effectiveBalanceIncrements clone Uint8Array 300000 71.497 us/op 26.972 us/op 2.65
effectiveBalanceIncrements clone MutableVector 300000 1.5950 us/op 364.00 ns/op 4.38
effectiveBalanceIncrements rw all Uint8Array 300000 175.97 us/op 167.11 us/op 1.05
effectiveBalanceIncrements rw all MutableVector 300000 168.67 ms/op 86.848 ms/op 1.94
phase0 afterProcessEpoch - 250000 vs - 7PWei 121.93 ms/op 113.60 ms/op 1.07
phase0 beforeProcessEpoch - 250000 vs - 7PWei 49.331 ms/op 42.130 ms/op 1.17
altair processEpoch - mainnet_e81889 373.96 ms/op 336.99 ms/op 1.11
mainnet_e81889 - altair beforeProcessEpoch 75.087 ms/op 65.252 ms/op 1.15
mainnet_e81889 - altair processJustificationAndFinalization 19.998 us/op 20.081 us/op 1.00
mainnet_e81889 - altair processInactivityUpdates 6.2407 ms/op 5.5917 ms/op 1.12
mainnet_e81889 - altair processRewardsAndPenalties 75.672 ms/op 68.716 ms/op 1.10
mainnet_e81889 - altair processRegistryUpdates 3.0000 us/op 2.7080 us/op 1.11
mainnet_e81889 - altair processSlashings 529.00 ns/op 416.00 ns/op 1.27
mainnet_e81889 - altair processEth1DataReset 496.00 ns/op 472.00 ns/op 1.05
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.5156 ms/op 1.2450 ms/op 1.22
mainnet_e81889 - altair processSlashingsReset 5.2280 us/op 6.6780 us/op 0.78
mainnet_e81889 - altair processRandaoMixesReset 4.8810 us/op 4.5860 us/op 1.06
mainnet_e81889 - altair processHistoricalRootsUpdate 590.00 ns/op 691.00 ns/op 0.85
mainnet_e81889 - altair processParticipationFlagUpdates 2.7650 us/op 2.7900 us/op 0.99
mainnet_e81889 - altair processSyncCommitteeUpdates 574.00 ns/op 477.00 ns/op 1.20
mainnet_e81889 - altair afterProcessEpoch 125.19 ms/op 119.57 ms/op 1.05
phase0 processEpoch - mainnet_e58758 361.27 ms/op 359.24 ms/op 1.01
mainnet_e58758 - phase0 beforeProcessEpoch 135.68 ms/op 118.33 ms/op 1.15
mainnet_e58758 - phase0 processJustificationAndFinalization 18.972 us/op 18.744 us/op 1.01
mainnet_e58758 - phase0 processRewardsAndPenalties 52.681 ms/op 53.120 ms/op 0.99
mainnet_e58758 - phase0 processRegistryUpdates 10.928 us/op 9.0260 us/op 1.21
mainnet_e58758 - phase0 processSlashings 529.00 ns/op 691.00 ns/op 0.77
mainnet_e58758 - phase0 processEth1DataReset 614.00 ns/op 911.00 ns/op 0.67
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.3888 ms/op 1.0694 ms/op 1.30
mainnet_e58758 - phase0 processSlashingsReset 5.2140 us/op 8.7260 us/op 0.60
mainnet_e58758 - phase0 processRandaoMixesReset 8.4530 us/op 6.2800 us/op 1.35
mainnet_e58758 - phase0 processHistoricalRootsUpdate 1.1290 us/op 1.0500 us/op 1.08
mainnet_e58758 - phase0 processParticipationRecordUpdates 7.4720 us/op 6.0350 us/op 1.24
mainnet_e58758 - phase0 afterProcessEpoch 100.90 ms/op 108.81 ms/op 0.93
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.5761 ms/op 1.2805 ms/op 1.23
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.7640 ms/op 1.5131 ms/op 1.17
altair processInactivityUpdates - 250000 normalcase 23.588 ms/op 31.694 ms/op 0.74
altair processInactivityUpdates - 250000 worstcase 29.545 ms/op 31.119 ms/op 0.95
phase0 processRegistryUpdates - 250000 normalcase 8.0630 us/op 7.6090 us/op 1.06
phase0 processRegistryUpdates - 250000 badcase_full_deposits 353.23 us/op 282.55 us/op 1.25
phase0 processRegistryUpdates - 250000 worstcase 0.5 138.98 ms/op 129.54 ms/op 1.07
altair processRewardsAndPenalties - 250000 normalcase 64.366 ms/op 67.912 ms/op 0.95
altair processRewardsAndPenalties - 250000 worstcase 57.281 ms/op 70.477 ms/op 0.81
phase0 getAttestationDeltas - 250000 normalcase 6.8584 ms/op 6.6152 ms/op 1.04
phase0 getAttestationDeltas - 250000 worstcase 6.9777 ms/op 6.6152 ms/op 1.05
phase0 processSlashings - 250000 worstcase 3.4355 ms/op 3.5179 ms/op 0.98
altair processSyncCommitteeUpdates - 250000 185.91 ms/op 178.25 ms/op 1.04
BeaconState.hashTreeRoot - No change 276.00 ns/op 287.00 ns/op 0.96
BeaconState.hashTreeRoot - 1 full validator 55.944 us/op 54.115 us/op 1.03
BeaconState.hashTreeRoot - 32 full validator 649.81 us/op 522.26 us/op 1.24
BeaconState.hashTreeRoot - 512 full validator 7.1931 ms/op 5.7720 ms/op 1.25
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 69.173 us/op 67.571 us/op 1.02
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 973.47 us/op 908.62 us/op 1.07
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 13.847 ms/op 11.362 ms/op 1.22
BeaconState.hashTreeRoot - 1 balances 52.365 us/op 51.670 us/op 1.01
BeaconState.hashTreeRoot - 32 balances 511.03 us/op 475.52 us/op 1.07
BeaconState.hashTreeRoot - 512 balances 4.9173 ms/op 4.6600 ms/op 1.06
BeaconState.hashTreeRoot - 250000 balances 82.403 ms/op 78.035 ms/op 1.06
aggregationBits - 2048 els - zipIndexesInBitList 18.189 us/op 17.640 us/op 1.03
regular array get 100000 times 34.202 us/op 34.921 us/op 0.98
wrappedArray get 100000 times 34.078 us/op 33.645 us/op 1.01
arrayWithProxy get 100000 times 16.490 ms/op 16.543 ms/op 1.00
ssz.Root.equals 600.00 ns/op 645.00 ns/op 0.93
byteArrayEquals 596.00 ns/op 600.00 ns/op 0.99
shuffle list - 16384 els 6.9638 ms/op 7.0164 ms/op 0.99
shuffle list - 250000 els 102.96 ms/op 103.38 ms/op 1.00
processSlot - 1 slots 9.9330 us/op 9.5260 us/op 1.04
processSlot - 32 slots 1.3759 ms/op 1.4200 ms/op 0.97
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 209.75 us/op 220.55 us/op 0.95
getCommitteeAssignments - req 1 vs - 250000 vc 3.0008 ms/op 2.9679 ms/op 1.01
getCommitteeAssignments - req 100 vs - 250000 vc 4.3063 ms/op 4.1616 ms/op 1.03
getCommitteeAssignments - req 1000 vs - 250000 vc 4.5875 ms/op 4.4698 ms/op 1.03
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 5.0400 ns/op 5.1400 ns/op 0.98
state getBlockRootAtSlot - 250000 vs - 7PWei 652.71 ns/op 851.32 ns/op 0.77
computeProposers - vc 250000 10.851 ms/op 11.298 ms/op 0.96
computeEpochShuffling - vc 250000 111.58 ms/op 104.04 ms/op 1.07
getNextSyncCommittee - vc 250000 183.48 ms/op 188.42 ms/op 0.97

by benchmarkbot/action

dapplion
dapplion previously approved these changes Feb 27, 2023
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.

LGTM

nazarhussain
nazarhussain previously approved these changes Feb 27, 2023
@nflaig nflaig dismissed stale reviews from nazarhussain and dapplion via 2af0054 February 27, 2023 21:09
@nflaig nflaig force-pushed the nflaig/disallow-destructuring-import branch from 7b9e1c3 to 2af0054 Compare February 27, 2023 21:09
@nflaig
Copy link
Member Author

nflaig commented Feb 27, 2023

rebased against unstable to get fc33339 in which fixes network e2e tests

@dapplion dapplion merged commit f10a95f into unstable Feb 28, 2023
@dapplion dapplion deleted the nflaig/disallow-destructuring-import branch February 28, 2023 04:09
@wemeetagain
Copy link
Member

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

Not use the import destructuring for some modules e.g. path
4 participants