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

chore: upgrade eslint and fix the warnings #6420

Merged
merged 7 commits into from
Feb 13, 2024
Merged

Conversation

nazarhussain
Copy link
Contributor

Motivation

Make the core more reliable.

Description

Fixing all the warnings in the code increase more reliability and trust on it.

Steps to test or reproduce

  • Run all tests.

@nazarhussain nazarhussain requested a review from a team as a code owner February 12, 2024 15:43
.eslintrc.js Outdated
@@ -64,6 +64,10 @@ module.exports = {
},
//ignore rules on destructured params
{selector: "variable", modifiers: ["destructured"], format: null},
{
selector: "import",
format: ["camelCase", "PascalCase"]
Copy link
Contributor Author

@nazarhussain nazarhussain Feb 12, 2024

Choose a reason for hiding this comment

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

This will allow to import packages like below without warnings.

import EventEmitter from "node:events";

.eslintrc.js Outdated
@@ -159,6 +163,7 @@ module.exports = {
"prettier/prettier": "error",
quotes: ["error", "double"],
semi: "off",
"import/namespace": "off",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/namespace.md

This rule is taking most of the linting time, 33% of the overall time.

This rule check each package usages at import time, but is not trivial to us as the non-existing methods can also be detected by unsafe-assignment rules.

import/namespace                              | 10715.327 |    33.2%

Copy link
Member

Choose a reason for hiding this comment

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

we should probably add a short comment in eslintrc to document it there as well

Copy link

codecov bot commented Feb 12, 2024

Codecov Report

Merging #6420 (09cd7e9) into unstable (da0bcc8) will increase coverage by 0.00%.
The diff coverage is 89.47%.

Additional details and impacted files
@@            Coverage Diff            @@
##           unstable    #6420   +/-   ##
=========================================
  Coverage     61.72%   61.72%           
=========================================
  Files           553      553           
  Lines         57856    57862    +6     
  Branches       1829     1829           
=========================================
+ Hits          35711    35717    +6     
  Misses        22108    22108           
  Partials         37       37           

packages/beacon-node/src/monitoring/system.ts Show resolved Hide resolved
packages/logger/src/winston.ts Outdated Show resolved Hide resolved
packages/test-utils/src/externalSigner.ts Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Feb 12, 2024

Performance Report

✔️ no performance regression detected

🚀🚀 Significant benchmark improvement detected

Benchmark suite Current: 3e6896b Previous: da0bcc8 Ratio
forkChoice updateHead vc 600000 bc 64 eq 300000 16.849 ms/op 59.814 ms/op 0.28
Full benchmark results
Benchmark suite Current: 3e6896b Previous: da0bcc8 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 579.79 us/op 584.31 us/op 0.99
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 90.557 us/op 103.46 us/op 0.88
BLS verify - blst-native 1.3546 ms/op 1.3286 ms/op 1.02
BLS verifyMultipleSignatures 3 - blst-native 2.8193 ms/op 2.7982 ms/op 1.01
BLS verifyMultipleSignatures 8 - blst-native 6.2409 ms/op 6.4121 ms/op 0.97
BLS verifyMultipleSignatures 32 - blst-native 22.438 ms/op 22.588 ms/op 0.99
BLS verifyMultipleSignatures 64 - blst-native 44.038 ms/op 44.555 ms/op 0.99
BLS verifyMultipleSignatures 128 - blst-native 86.400 ms/op 88.253 ms/op 0.98
BLS deserializing 10000 signatures 984.48 ms/op 953.60 ms/op 1.03
BLS deserializing 100000 signatures 9.6307 s/op 9.1787 s/op 1.05
BLS verifyMultipleSignatures - same message - 3 - blst-native 1.6547 ms/op 1.3956 ms/op 1.19
BLS verifyMultipleSignatures - same message - 8 - blst-native 1.7518 ms/op 1.5960 ms/op 1.10
BLS verifyMultipleSignatures - same message - 32 - blst-native 2.7702 ms/op 2.3926 ms/op 1.16
BLS verifyMultipleSignatures - same message - 64 - blst-native 3.9831 ms/op 3.5314 ms/op 1.13
BLS verifyMultipleSignatures - same message - 128 - blst-native 6.4001 ms/op 5.9130 ms/op 1.08
BLS aggregatePubkeys 32 - blst-native 28.423 us/op 27.189 us/op 1.05
BLS aggregatePubkeys 128 - blst-native 113.40 us/op 104.69 us/op 1.08
notSeenSlots=1 numMissedVotes=1 numBadVotes=10 74.251 ms/op 74.780 ms/op 0.99
notSeenSlots=1 numMissedVotes=0 numBadVotes=4 72.022 ms/op 77.285 ms/op 0.93
notSeenSlots=2 numMissedVotes=1 numBadVotes=10 55.649 ms/op 61.405 ms/op 0.91
getSlashingsAndExits - default max 291.55 us/op 413.90 us/op 0.70
getSlashingsAndExits - 2k 383.29 us/op 601.99 us/op 0.64
proposeBlockBody type=full, size=empty 6.2960 ms/op 7.3645 ms/op 0.85
isKnown best case - 1 super set check 502.00 ns/op 603.00 ns/op 0.83
isKnown normal case - 2 super set checks 513.00 ns/op 638.00 ns/op 0.80
isKnown worse case - 16 super set checks 582.00 ns/op 600.00 ns/op 0.97
CheckpointStateCache - add get delete 7.1130 us/op 6.6010 us/op 1.08
validate api signedAggregateAndProof - struct 3.0493 ms/op 2.8612 ms/op 1.07
validate gossip signedAggregateAndProof - struct 2.9927 ms/op 2.8658 ms/op 1.04
validate gossip attestation - vc 640000 1.4626 ms/op 1.5069 ms/op 0.97
batch validate gossip attestation - vc 640000 - chunk 32 168.87 us/op 178.65 us/op 0.95
batch validate gossip attestation - vc 640000 - chunk 64 148.37 us/op 166.95 us/op 0.89
batch validate gossip attestation - vc 640000 - chunk 128 140.42 us/op 174.67 us/op 0.80
batch validate gossip attestation - vc 640000 - chunk 256 141.53 us/op 149.41 us/op 0.95
pickEth1Vote - no votes 1.3036 ms/op 1.3603 ms/op 0.96
pickEth1Vote - max votes 10.413 ms/op 10.938 ms/op 0.95
pickEth1Vote - Eth1Data hashTreeRoot value x2048 16.975 ms/op 21.652 ms/op 0.78
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 34.919 ms/op 32.850 ms/op 1.06
pickEth1Vote - Eth1Data fastSerialize value x2048 650.35 us/op 780.24 us/op 0.83
pickEth1Vote - Eth1Data fastSerialize tree x2048 4.3200 ms/op 7.3537 ms/op 0.59
bytes32 toHexString 541.00 ns/op 788.00 ns/op 0.69
bytes32 Buffer.toString(hex) 306.00 ns/op 336.00 ns/op 0.91
bytes32 Buffer.toString(hex) from Uint8Array 441.00 ns/op 603.00 ns/op 0.73
bytes32 Buffer.toString(hex) + 0x 298.00 ns/op 353.00 ns/op 0.84
Object access 1 prop 0.18500 ns/op 0.26000 ns/op 0.71
Map access 1 prop 0.16200 ns/op 0.16100 ns/op 1.01
Object get x1000 7.3990 ns/op 11.084 ns/op 0.67
Map get x1000 0.85700 ns/op 0.95400 ns/op 0.90
Object set x1000 59.629 ns/op 82.526 ns/op 0.72
Map set x1000 45.820 ns/op 58.246 ns/op 0.79
Return object 10000 times 0.25670 ns/op 0.35470 ns/op 0.72
Throw Error 10000 times 3.9639 us/op 4.2510 us/op 0.93
fastMsgIdFn sha256 / 200 bytes 3.3970 us/op 3.5150 us/op 0.97
fastMsgIdFn h32 xxhash / 200 bytes 305.00 ns/op 373.00 ns/op 0.82
fastMsgIdFn h64 xxhash / 200 bytes 361.00 ns/op 424.00 ns/op 0.85
fastMsgIdFn sha256 / 1000 bytes 11.830 us/op 12.307 us/op 0.96
fastMsgIdFn h32 xxhash / 1000 bytes 451.00 ns/op 536.00 ns/op 0.84
fastMsgIdFn h64 xxhash / 1000 bytes 462.00 ns/op 520.00 ns/op 0.89
fastMsgIdFn sha256 / 10000 bytes 106.93 us/op 110.36 us/op 0.97
fastMsgIdFn h32 xxhash / 10000 bytes 2.0210 us/op 2.1120 us/op 0.96
fastMsgIdFn h64 xxhash / 10000 bytes 1.3720 us/op 1.5040 us/op 0.91
send data - 1000 256B messages 18.144 ms/op 28.096 ms/op 0.65
send data - 1000 512B messages 24.332 ms/op 30.978 ms/op 0.79
send data - 1000 1024B messages 45.236 ms/op 59.815 ms/op 0.76
send data - 1000 1200B messages 39.999 ms/op 50.763 ms/op 0.79
send data - 1000 2048B messages 52.792 ms/op 56.103 ms/op 0.94
send data - 1000 4096B messages 43.668 ms/op 55.215 ms/op 0.79
send data - 1000 16384B messages 122.34 ms/op 138.40 ms/op 0.88
send data - 1000 65536B messages 427.90 ms/op 569.69 ms/op 0.75
enrSubnets - fastDeserialize 64 bits 1.2490 us/op 1.9070 us/op 0.65
enrSubnets - ssz BitVector 64 bits 459.00 ns/op 599.00 ns/op 0.77
enrSubnets - fastDeserialize 4 bits 178.00 ns/op 236.00 ns/op 0.75
enrSubnets - ssz BitVector 4 bits 466.00 ns/op 629.00 ns/op 0.74
prioritizePeers score -10:0 att 32-0.1 sync 2-0 129.88 us/op 133.11 us/op 0.98
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 134.15 us/op 169.56 us/op 0.79
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 176.59 us/op 216.55 us/op 0.82
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 300.85 us/op 418.85 us/op 0.72
prioritizePeers score 0:0 att 64-1 sync 4-1 336.57 us/op 438.79 us/op 0.77
array of 16000 items push then shift 1.6767 us/op 1.9359 us/op 0.87
LinkedList of 16000 items push then shift 8.8170 ns/op 11.645 ns/op 0.76
array of 16000 items push then pop 75.691 ns/op 134.67 ns/op 0.56
LinkedList of 16000 items push then pop 8.9570 ns/op 16.601 ns/op 0.54
array of 24000 items push then shift 2.4788 us/op 3.1907 us/op 0.78
LinkedList of 24000 items push then shift 9.0440 ns/op 11.260 ns/op 0.80
array of 24000 items push then pop 110.20 ns/op 171.94 ns/op 0.64
LinkedList of 24000 items push then pop 8.5430 ns/op 10.373 ns/op 0.82
intersect bitArray bitLen 8 5.6680 ns/op 8.4990 ns/op 0.67
intersect array and set length 8 62.958 ns/op 128.21 ns/op 0.49
intersect bitArray bitLen 128 35.316 ns/op 47.090 ns/op 0.75
intersect array and set length 128 860.04 ns/op 1.2481 us/op 0.69
bitArray.getTrueBitIndexes() bitLen 128 1.4880 us/op 2.0650 us/op 0.72
bitArray.getTrueBitIndexes() bitLen 248 2.5650 us/op 3.5730 us/op 0.72
bitArray.getTrueBitIndexes() bitLen 512 4.9380 us/op 8.3480 us/op 0.59
Buffer.concat 32 items 959.00 ns/op 1.2530 us/op 0.77
Uint8Array.set 32 items 1.6960 us/op 3.3210 us/op 0.51
Set add up to 64 items then delete first 4.2447 us/op 6.0273 us/op 0.70
OrderedSet add up to 64 items then delete first 5.7106 us/op 8.1330 us/op 0.70
Set add up to 64 items then delete last 4.8143 us/op 6.7598 us/op 0.71
OrderedSet add up to 64 items then delete last 5.8672 us/op 8.0896 us/op 0.73
Set add up to 64 items then delete middle 4.6872 us/op 6.2399 us/op 0.75
OrderedSet add up to 64 items then delete middle 7.2078 us/op 10.031 us/op 0.72
Set add up to 128 items then delete first 9.5728 us/op 12.475 us/op 0.77
OrderedSet add up to 128 items then delete first 12.945 us/op 16.317 us/op 0.79
Set add up to 128 items then delete last 9.6154 us/op 12.098 us/op 0.79
OrderedSet add up to 128 items then delete last 11.991 us/op 16.019 us/op 0.75
Set add up to 128 items then delete middle 9.2914 us/op 12.104 us/op 0.77
OrderedSet add up to 128 items then delete middle 17.322 us/op 25.909 us/op 0.67
Set add up to 256 items then delete first 19.057 us/op 24.704 us/op 0.77
OrderedSet add up to 256 items then delete first 26.208 us/op 35.228 us/op 0.74
Set add up to 256 items then delete last 18.758 us/op 23.556 us/op 0.80
OrderedSet add up to 256 items then delete last 24.867 us/op 34.129 us/op 0.73
Set add up to 256 items then delete middle 18.539 us/op 23.349 us/op 0.79
OrderedSet add up to 256 items then delete middle 46.605 us/op 64.899 us/op 0.72
transfer serialized Status (84 B) 1.7230 us/op 2.2370 us/op 0.77
copy serialized Status (84 B) 1.2420 us/op 1.8340 us/op 0.68
transfer serialized SignedVoluntaryExit (112 B) 1.8240 us/op 2.6600 us/op 0.69
copy serialized SignedVoluntaryExit (112 B) 1.3180 us/op 1.6820 us/op 0.78
transfer serialized ProposerSlashing (416 B) 2.0710 us/op 3.1880 us/op 0.65
copy serialized ProposerSlashing (416 B) 2.8330 us/op 2.5990 us/op 1.09
transfer serialized Attestation (485 B) 3.3400 us/op 2.8750 us/op 1.16
copy serialized Attestation (485 B) 3.0410 us/op 3.1800 us/op 0.96
transfer serialized AttesterSlashing (33232 B) 3.3460 us/op 3.5950 us/op 0.93
copy serialized AttesterSlashing (33232 B) 7.5520 us/op 10.526 us/op 0.72
transfer serialized Small SignedBeaconBlock (128000 B) 3.8020 us/op 4.3980 us/op 0.86
copy serialized Small SignedBeaconBlock (128000 B) 15.543 us/op 32.857 us/op 0.47
transfer serialized Avg SignedBeaconBlock (200000 B) 3.9170 us/op 5.5130 us/op 0.71
copy serialized Avg SignedBeaconBlock (200000 B) 24.103 us/op 50.285 us/op 0.48
transfer serialized BlobsSidecar (524380 B) 3.9720 us/op 6.7480 us/op 0.59
copy serialized BlobsSidecar (524380 B) 84.396 us/op 161.23 us/op 0.52
transfer serialized Big SignedBeaconBlock (1000000 B) 4.0090 us/op 6.1200 us/op 0.66
copy serialized Big SignedBeaconBlock (1000000 B) 170.64 us/op 274.53 us/op 0.62
pass gossip attestations to forkchoice per slot 4.4451 ms/op 4.7416 ms/op 0.94
forkChoice updateHead vc 100000 bc 64 eq 0 758.67 us/op 788.12 us/op 0.96
forkChoice updateHead vc 600000 bc 64 eq 0 4.3438 ms/op 5.5718 ms/op 0.78
forkChoice updateHead vc 1000000 bc 64 eq 0 7.4889 ms/op 8.6122 ms/op 0.87
forkChoice updateHead vc 600000 bc 320 eq 0 4.2738 ms/op 5.4914 ms/op 0.78
forkChoice updateHead vc 600000 bc 1200 eq 0 4.2928 ms/op 5.6945 ms/op 0.75
forkChoice updateHead vc 600000 bc 7200 eq 0 5.3293 ms/op 9.9126 ms/op 0.54
forkChoice updateHead vc 600000 bc 64 eq 1000 11.425 ms/op 12.572 ms/op 0.91
forkChoice updateHead vc 600000 bc 64 eq 10000 12.273 ms/op 14.893 ms/op 0.82
forkChoice updateHead vc 600000 bc 64 eq 300000 16.849 ms/op 59.814 ms/op 0.28
computeDeltas 500000 validators 300 proto nodes 6.7828 ms/op 8.2483 ms/op 0.82
computeDeltas 500000 validators 1200 proto nodes 6.7742 ms/op 7.6901 ms/op 0.88
computeDeltas 500000 validators 7200 proto nodes 6.6770 ms/op 6.9251 ms/op 0.96
computeDeltas 750000 validators 300 proto nodes 10.502 ms/op 9.9810 ms/op 1.05
computeDeltas 750000 validators 1200 proto nodes 10.311 ms/op 10.451 ms/op 0.99
computeDeltas 750000 validators 7200 proto nodes 10.506 ms/op 10.065 ms/op 1.04
computeDeltas 1400000 validators 300 proto nodes 20.565 ms/op 20.570 ms/op 1.00
computeDeltas 1400000 validators 1200 proto nodes 20.463 ms/op 19.252 ms/op 1.06
computeDeltas 1400000 validators 7200 proto nodes 19.862 ms/op 19.751 ms/op 1.01
computeDeltas 2100000 validators 300 proto nodes 30.117 ms/op 31.508 ms/op 0.96
computeDeltas 2100000 validators 1200 proto nodes 29.703 ms/op 32.215 ms/op 0.92
computeDeltas 2100000 validators 7200 proto nodes 28.751 ms/op 30.927 ms/op 0.93
altair processAttestation - 250000 vs - 7PWei normalcase 2.2523 ms/op 2.5199 ms/op 0.89
altair processAttestation - 250000 vs - 7PWei worstcase 3.3343 ms/op 4.2263 ms/op 0.79
altair processAttestation - setStatus - 1/6 committees join 150.13 us/op 207.75 us/op 0.72
altair processAttestation - setStatus - 1/3 committees join 299.26 us/op 401.95 us/op 0.74
altair processAttestation - setStatus - 1/2 committees join 407.47 us/op 503.53 us/op 0.81
altair processAttestation - setStatus - 2/3 committees join 495.78 us/op 673.96 us/op 0.74
altair processAttestation - setStatus - 4/5 committees join 724.11 us/op 858.02 us/op 0.84
altair processAttestation - setStatus - 100% committees join 836.79 us/op 970.11 us/op 0.86
altair processBlock - 250000 vs - 7PWei normalcase 9.9944 ms/op 11.390 ms/op 0.88
altair processBlock - 250000 vs - 7PWei normalcase hashState 39.935 ms/op 45.452 ms/op 0.88
altair processBlock - 250000 vs - 7PWei worstcase 40.921 ms/op 42.842 ms/op 0.96
altair processBlock - 250000 vs - 7PWei worstcase hashState 101.64 ms/op 119.45 ms/op 0.85
phase0 processBlock - 250000 vs - 7PWei normalcase 3.1291 ms/op 4.0276 ms/op 0.78
phase0 processBlock - 250000 vs - 7PWei worstcase 31.740 ms/op 32.873 ms/op 0.97
altair processEth1Data - 250000 vs - 7PWei normalcase 623.64 us/op 761.56 us/op 0.82
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 8.2980 us/op 19.608 us/op 0.42
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 43.118 us/op 97.580 us/op 0.44
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 19.522 us/op 37.925 us/op 0.51
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 15.707 us/op 24.529 us/op 0.64
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 168.58 us/op 287.11 us/op 0.59
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.6313 ms/op 1.6573 ms/op 0.98
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.9751 ms/op 2.5652 ms/op 0.77
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 2.0741 ms/op 1.9100 ms/op 1.09
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 4.3216 ms/op 4.9796 ms/op 0.87
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 3.0008 ms/op 3.1763 ms/op 0.94
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 5.7565 ms/op 6.3513 ms/op 0.91
Tree 40 250000 create 416.77 ms/op 521.59 ms/op 0.80
Tree 40 250000 get(125000) 234.65 ns/op 222.92 ns/op 1.05
Tree 40 250000 set(125000) 1.1880 us/op 1.4545 us/op 0.82
Tree 40 250000 toArray() 23.205 ms/op 29.102 ms/op 0.80
Tree 40 250000 iterate all - toArray() + loop 22.015 ms/op 26.292 ms/op 0.84
Tree 40 250000 iterate all - get(i) 78.348 ms/op 75.958 ms/op 1.03
MutableVector 250000 create 18.567 ms/op 13.347 ms/op 1.39
MutableVector 250000 get(125000) 6.8520 ns/op 6.6420 ns/op 1.03
MutableVector 250000 set(125000) 284.74 ns/op 495.86 ns/op 0.57
MutableVector 250000 toArray() 3.5556 ms/op 4.5560 ms/op 0.78
MutableVector 250000 iterate all - toArray() + loop 3.7928 ms/op 4.5750 ms/op 0.83
MutableVector 250000 iterate all - get(i) 1.5730 ms/op 1.5613 ms/op 1.01
Array 250000 create 3.4223 ms/op 3.3906 ms/op 1.01
Array 250000 clone - spread 1.3479 ms/op 1.3892 ms/op 0.97
Array 250000 get(125000) 1.1090 ns/op 1.1310 ns/op 0.98
Array 250000 set(125000) 4.3520 ns/op 4.4160 ns/op 0.99
Array 250000 iterate all - loop 173.16 us/op 170.57 us/op 1.02
effectiveBalanceIncrements clone Uint8Array 300000 31.622 us/op 44.535 us/op 0.71
effectiveBalanceIncrements clone MutableVector 300000 410.00 ns/op 405.00 ns/op 1.01
effectiveBalanceIncrements rw all Uint8Array 300000 205.96 us/op 204.05 us/op 1.01
effectiveBalanceIncrements rw all MutableVector 300000 93.419 ms/op 94.994 ms/op 0.98
phase0 afterProcessEpoch - 250000 vs - 7PWei 121.41 ms/op 114.60 ms/op 1.06
phase0 beforeProcessEpoch - 250000 vs - 7PWei 57.571 ms/op 50.392 ms/op 1.14
altair processEpoch - mainnet_e81889 535.07 ms/op 587.64 ms/op 0.91
mainnet_e81889 - altair beforeProcessEpoch 89.192 ms/op 87.200 ms/op 1.02
mainnet_e81889 - altair processJustificationAndFinalization 23.063 us/op 20.800 us/op 1.11
mainnet_e81889 - altair processInactivityUpdates 7.3941 ms/op 6.8303 ms/op 1.08
mainnet_e81889 - altair processRewardsAndPenalties 51.492 ms/op 76.364 ms/op 0.67
mainnet_e81889 - altair processRegistryUpdates 2.9730 us/op 2.5830 us/op 1.15
mainnet_e81889 - altair processSlashings 549.00 ns/op 896.00 ns/op 0.61
mainnet_e81889 - altair processEth1DataReset 1.1230 us/op 1.1670 us/op 0.96
mainnet_e81889 - altair processEffectiveBalanceUpdates 2.7610 ms/op 2.7135 ms/op 1.02
mainnet_e81889 - altair processSlashingsReset 3.9500 us/op 9.9090 us/op 0.40
mainnet_e81889 - altair processRandaoMixesReset 6.3830 us/op 8.4300 us/op 0.76
mainnet_e81889 - altair processHistoricalRootsUpdate 1.1430 us/op 1.0360 us/op 1.10
mainnet_e81889 - altair processParticipationFlagUpdates 3.4560 us/op 2.8150 us/op 1.23
mainnet_e81889 - altair processSyncCommitteeUpdates 679.00 ns/op 883.00 ns/op 0.77
mainnet_e81889 - altair afterProcessEpoch 129.41 ms/op 124.13 ms/op 1.04
capella processEpoch - mainnet_e217614 2.2908 s/op 3.0721 s/op 0.75
mainnet_e217614 - capella beforeProcessEpoch 524.31 ms/op 646.41 ms/op 0.81
mainnet_e217614 - capella processJustificationAndFinalization 18.697 us/op 25.497 us/op 0.73
mainnet_e217614 - capella processInactivityUpdates 18.358 ms/op 26.025 ms/op 0.71
mainnet_e217614 - capella processRewardsAndPenalties 425.26 ms/op 441.35 ms/op 0.96
mainnet_e217614 - capella processRegistryUpdates 29.408 us/op 27.680 us/op 1.06
mainnet_e217614 - capella processSlashings 903.00 ns/op 922.00 ns/op 0.98
mainnet_e217614 - capella processEth1DataReset 754.00 ns/op 529.00 ns/op 1.43
mainnet_e217614 - capella processEffectiveBalanceUpdates 8.7567 ms/op 4.5719 ms/op 1.92
mainnet_e217614 - capella processSlashingsReset 4.4130 us/op 3.6690 us/op 1.20
mainnet_e217614 - capella processRandaoMixesReset 6.4930 us/op 5.2020 us/op 1.25
mainnet_e217614 - capella processHistoricalRootsUpdate 630.00 ns/op 811.00 ns/op 0.78
mainnet_e217614 - capella processParticipationFlagUpdates 1.8020 us/op 3.3180 us/op 0.54
mainnet_e217614 - capella afterProcessEpoch 318.86 ms/op 325.16 ms/op 0.98
phase0 processEpoch - mainnet_e58758 493.08 ms/op 517.88 ms/op 0.95
mainnet_e58758 - phase0 beforeProcessEpoch 155.35 ms/op 147.65 ms/op 1.05
mainnet_e58758 - phase0 processJustificationAndFinalization 17.586 us/op 15.962 us/op 1.10
mainnet_e58758 - phase0 processRewardsAndPenalties 62.738 ms/op 41.414 ms/op 1.51
mainnet_e58758 - phase0 processRegistryUpdates 13.059 us/op 10.715 us/op 1.22
mainnet_e58758 - phase0 processSlashings 694.00 ns/op 695.00 ns/op 1.00
mainnet_e58758 - phase0 processEth1DataReset 726.00 ns/op 502.00 ns/op 1.45
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 1.1563 ms/op 1.2391 ms/op 0.93
mainnet_e58758 - phase0 processSlashingsReset 3.3410 us/op 8.6120 us/op 0.39
mainnet_e58758 - phase0 processRandaoMixesReset 6.1730 us/op 7.9720 us/op 0.77
mainnet_e58758 - phase0 processHistoricalRootsUpdate 830.00 ns/op 920.00 ns/op 0.90
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.9540 us/op 5.9000 us/op 0.84
mainnet_e58758 - phase0 afterProcessEpoch 102.83 ms/op 101.52 ms/op 1.01
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.4244 ms/op 1.6733 ms/op 0.85
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.5491 ms/op 1.9521 ms/op 0.79
altair processInactivityUpdates - 250000 normalcase 28.386 ms/op 29.944 ms/op 0.95
altair processInactivityUpdates - 250000 worstcase 33.515 ms/op 28.211 ms/op 1.19
phase0 processRegistryUpdates - 250000 normalcase 12.497 us/op 14.414 us/op 0.87
phase0 processRegistryUpdates - 250000 badcase_full_deposits 523.13 us/op 572.92 us/op 0.91
phase0 processRegistryUpdates - 250000 worstcase 0.5 150.11 ms/op 139.71 ms/op 1.07
altair processRewardsAndPenalties - 250000 normalcase 66.076 ms/op 61.519 ms/op 1.07
altair processRewardsAndPenalties - 250000 worstcase 66.220 ms/op 61.884 ms/op 1.07
phase0 getAttestationDeltas - 250000 normalcase 10.714 ms/op 9.0644 ms/op 1.18
phase0 getAttestationDeltas - 250000 worstcase 10.915 ms/op 8.8604 ms/op 1.23
phase0 processSlashings - 250000 worstcase 132.08 us/op 130.14 us/op 1.01
altair processSyncCommitteeUpdates - 250000 168.49 ms/op 151.58 ms/op 1.11
BeaconState.hashTreeRoot - No change 684.00 ns/op 380.00 ns/op 1.80
BeaconState.hashTreeRoot - 1 full validator 134.35 us/op 126.93 us/op 1.06
BeaconState.hashTreeRoot - 32 full validator 1.3108 ms/op 1.2962 ms/op 1.01
BeaconState.hashTreeRoot - 512 full validator 17.556 ms/op 12.976 ms/op 1.35
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 186.33 us/op 139.83 us/op 1.33
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 2.5984 ms/op 1.8468 ms/op 1.41
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 34.333 ms/op 23.910 ms/op 1.44
BeaconState.hashTreeRoot - 1 balances 162.78 us/op 108.18 us/op 1.50
BeaconState.hashTreeRoot - 32 balances 1.6744 ms/op 990.52 us/op 1.69
BeaconState.hashTreeRoot - 512 balances 11.885 ms/op 10.556 ms/op 1.13
BeaconState.hashTreeRoot - 250000 balances 208.15 ms/op 216.91 ms/op 0.96
aggregationBits - 2048 els - zipIndexesInBitList 18.056 us/op 18.685 us/op 0.97
byteArrayEquals 32 79.618 ns/op 76.711 ns/op 1.04
Buffer.compare 32 58.019 ns/op 56.504 ns/op 1.03
byteArrayEquals 1024 2.1146 us/op 2.0921 us/op 1.01
Buffer.compare 1024 73.225 ns/op 71.583 ns/op 1.02
byteArrayEquals 16384 34.012 us/op 33.282 us/op 1.02
Buffer.compare 16384 252.94 ns/op 253.95 ns/op 1.00
byteArrayEquals 123687377 261.62 ms/op 262.41 ms/op 1.00
Buffer.compare 123687377 6.8123 ms/op 8.5577 ms/op 0.80
byteArrayEquals 32 - diff last byte 80.823 ns/op 85.578 ns/op 0.94
Buffer.compare 32 - diff last byte 58.529 ns/op 60.581 ns/op 0.97
byteArrayEquals 1024 - diff last byte 2.1149 us/op 2.3409 us/op 0.90
Buffer.compare 1024 - diff last byte 73.589 ns/op 74.334 ns/op 0.99
byteArrayEquals 16384 - diff last byte 33.688 us/op 34.824 us/op 0.97
Buffer.compare 16384 - diff last byte 252.13 ns/op 294.52 ns/op 0.86
byteArrayEquals 123687377 - diff last byte 254.37 ms/op 268.06 ms/op 0.95
Buffer.compare 123687377 - diff last byte 6.6712 ms/op 8.3847 ms/op 0.80
byteArrayEquals 32 - random bytes 5.5900 ns/op 5.4650 ns/op 1.02
Buffer.compare 32 - random bytes 63.911 ns/op 63.591 ns/op 1.01
byteArrayEquals 1024 - random bytes 5.8260 ns/op 5.7690 ns/op 1.01
Buffer.compare 1024 - random bytes 64.330 ns/op 62.113 ns/op 1.04
byteArrayEquals 16384 - random bytes 5.5750 ns/op 5.7090 ns/op 0.98
Buffer.compare 16384 - random bytes 62.909 ns/op 62.721 ns/op 1.00
byteArrayEquals 123687377 - random bytes 8.9300 ns/op 9.0500 ns/op 0.99
Buffer.compare 123687377 - random bytes 77.690 ns/op 73.230 ns/op 1.06
regular array get 100000 times 49.539 us/op 46.242 us/op 1.07
wrappedArray get 100000 times 49.548 us/op 46.529 us/op 1.06
arrayWithProxy get 100000 times 15.424 ms/op 14.781 ms/op 1.04
ssz.Root.equals 57.241 ns/op 55.281 ns/op 1.04
byteArrayEquals 56.125 ns/op 55.507 ns/op 1.01
Buffer.compare 12.126 ns/op 12.055 ns/op 1.01
shuffle list - 16384 els 7.2527 ms/op 7.1632 ms/op 1.01
shuffle list - 250000 els 107.95 ms/op 105.93 ms/op 1.02
processSlot - 1 slots 19.856 us/op 20.794 us/op 0.95
processSlot - 32 slots 4.4545 ms/op 4.4451 ms/op 1.00
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 62.741 ms/op 63.881 ms/op 0.98
getCommitteeAssignments - req 1 vs - 250000 vc 2.6144 ms/op 2.5847 ms/op 1.01
getCommitteeAssignments - req 100 vs - 250000 vc 3.8864 ms/op 3.8028 ms/op 1.02
getCommitteeAssignments - req 1000 vs - 250000 vc 4.2812 ms/op 4.2971 ms/op 1.00
findModifiedValidators - 10000 modified validators 556.65 ms/op 591.52 ms/op 0.94
findModifiedValidators - 1000 modified validators 446.18 ms/op 515.23 ms/op 0.87
findModifiedValidators - 100 modified validators 411.15 ms/op 578.79 ms/op 0.71
findModifiedValidators - 10 modified validators 435.29 ms/op 621.71 ms/op 0.70
findModifiedValidators - 1 modified validators 421.02 ms/op 563.91 ms/op 0.75
findModifiedValidators - no difference 422.83 ms/op 569.46 ms/op 0.74
compare ViewDUs 5.0181 s/op 7.0146 s/op 0.72
compare each validator Uint8Array 1.9133 s/op 2.8349 s/op 0.67
compare ViewDU to Uint8Array 1.3177 s/op 1.8915 s/op 0.70
migrate state 1000000 validators, 24 modified, 0 new 865.16 ms/op 1.1145 s/op 0.78
migrate state 1000000 validators, 1700 modified, 1000 new 1.1835 s/op 1.2479 s/op 0.95
migrate state 1000000 validators, 3400 modified, 2000 new 1.3448 s/op 1.5435 s/op 0.87
migrate state 1500000 validators, 24 modified, 0 new 855.19 ms/op 934.39 ms/op 0.92
migrate state 1500000 validators, 1700 modified, 1000 new 1.1611 s/op 1.4982 s/op 0.78
migrate state 1500000 validators, 3400 modified, 2000 new 1.3684 s/op 1.8684 s/op 0.73
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 4.5000 ns/op 5.8100 ns/op 0.77
state getBlockRootAtSlot - 250000 vs - 7PWei 687.46 ns/op 821.08 ns/op 0.84
computeProposers - vc 250000 9.7353 ms/op 13.372 ms/op 0.73
computeEpochShuffling - vc 250000 109.93 ms/op 126.25 ms/op 0.87
getNextSyncCommittee - vc 250000 170.89 ms/op 202.42 ms/op 0.84
computeSigningRoot for AttestationData 25.561 us/op 35.716 us/op 0.72
hash AttestationData serialized data then Buffer.toString(base64) 2.4275 us/op 2.6142 us/op 0.93
toHexString serialized data 1.1353 us/op 1.7479 us/op 0.65
Buffer.toString(base64) 249.52 ns/op 284.84 ns/op 0.88

by benchmarkbot/action

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

Looking at the diff of this PR is makes it pretty clear that import/no-named-as-default and import/no-named-as-default-member are not helpful eslint rules.

The stated rationale in no-named-as-default-member and no-named-as-default.md doesn't sounds convincing to me

Rationale: Accessing a property that has a name that is shared by an exported name from the same module is likely to be a mistake.

Named import syntax looks very similar to destructuring assignment. It's easy to make the (incorrect) assumption that named exports are also accessible as properties of the default export.

I don't see how this prevents actual issues especially since we use typescript which won't allow us to access properties that do not exist. Looking at the diff of the PR, those rules look like a net negative to me.

Maybe someone can make a strong argument why we should keep those, else I would suggest to disable them

@nazarhussain
Copy link
Contributor Author

Looking at the diff of this PR is makes it pretty clear that import/no-named-as-default and import/no-named-as-default-member are not helpful eslint rules.

The rule import/no-named-as-default-member is helpful to enforce destructuring import for named exports.

// Caution: `foo` also has a named export `bar`.
// Check if you meant to write `import {bar} from './foo.js'` instead.

and the rule import/no-named-as-default enforces to use same identifier for default export. Which is good in reference to external libraries. e.g. import myPackage from 'lodash' will warn you to use import lodash from 'lodash'` because this package have a default export with this identifier. This makes consistent identifier of a package across different codebases.

// foo.js
export default 'foo';

// message: Using exported name 'bar' as identifier for default export.
import bar from './foo.js';

@nflaig
Copy link
Member

nflaig commented Feb 13, 2024

That's what the examples show in the .md files of the rules as well but I don't see how that is useful in a typed system

why is this

import {stringify as queryStringStringify} from "qs";
queryStringStringify(...)

better than this

import qs from "qs";
qs.stringify(...)

if the qs package has a default export then second example looks perfectly fine to me, in fact, the syntax is more readable / concise.

Ideally, the function call should be clear without looking at imports. And having qs. make it more obvious that this is from qs package and not a custom function we implemented.

Is there one example in our code where those rules are helpful?

@nazarhussain
Copy link
Contributor Author

nazarhussain commented Feb 13, 2024

if the qs package has a default export then second example looks perfectly fine to me, in fact, the syntax is more readable / concise.

Because you import more than what you need, which is a bad practice. The whole package may come with some side effects. So why destructured import and named exports was first introduced in ES and so why it's considered recommended by community by adding these rules to that recommended list.

@nflaig
Copy link
Member

nflaig commented Feb 13, 2024

The whole package may come with some side effects

Unless I completely misunderstand how ES modules are loaded there is no difference in destructuring or not, this seems to be confirmed here. And to take advantage of tree shaking I think it is only possible if the package architecture allows for it.

by adding these rules to that recommended list.

The stated rationale of those rules has nothing to do what you just mentioned, maybe we need a rule then that forces you to always destructure imports but sounds like a big pain to me as native nodejs libs are designed (for better semantics) to be used via default export

Copy link
Member

@nflaig nflaig left a comment

Choose a reason for hiding this comment

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

While I don't see the usefulness of these eslint rules, I don't feel strongly enough about it to further discuss this

@nazarhussain
Copy link
Contributor Author

Unless I completely misunderstand how ES modules are loaded there is no difference in destructuring or not, this seems to be confirmed here. And to take advantage of tree shaking I think it is only possible if the package architecture allows for it.

Destructruing allows to remove to dead code and production builds should strip all such cases. CommonJS didn't allowed that which is referred in your link, so why ES is considered better JS modules approach.

And any module may have side effect or not, or our building process handle dead code or not, one can't think of all such cases while writing the code. While writing you just follow the best practices and leave rest extra tooling and future improvements in that tooling. Using destructuring imports for named exports is commonly known best practice, so why added into linting recommended config. And when we discuss import specific rules, we don't include CommonJS in that discussion.

@nazarhussain nazarhussain merged commit ae61683 into unstable Feb 13, 2024
12 of 15 checks passed
@nazarhussain nazarhussain deleted the nh/eslint-warnings branch February 13, 2024 16:19
@nflaig
Copy link
Member

nflaig commented Feb 13, 2024

@nazarhussain interesting article about tree shaking

The conclusion

Tree Shaking have you covered! You can import however you want and you will be getting a healthy bundle if and only if the library has support for ES6 Module Syntax (import and export).

And for commonjs packages you will have to import from like this

import has from 'lodash/has';
import capitalize from 'lodash/capitalize';
import lastIndexOf from 'lodash/lastIndexOf';

So again, I don't see how those rules help us here 🤷

@nazarhussain
Copy link
Contributor Author

Tree Shaking have you covered! You can import however you want and you will be getting a healthy bundle if and only if the library has support for ES6 Module Syntax (import and export).

Tree shaking and detecting dead code behavior is slightly different among builders e.g. Webpack, ES-Build, Rollup, TSC. While writing code you don't worry about which tool is used and what future improvements in those tools are expected to appear.

Any future release of Webpack may improve some edge case which it does not before and you would not like to rewrite your code when it does. So if you follow a practice recommended by community, tools like Webpack will keep improving around those practices.

@wemeetagain
Copy link
Member

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