Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement isomorphic utils for nodejs and browser #7060

Merged
merged 3 commits into from
Aug 30, 2024

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Aug 29, 2024

Motivation

  • implement isomorphic utils for nodejs and browser
  • try nodejs first, if not use browser version

Description

  • the 3 utils are: toHex, toRootHex and fromHex
    • remove from bytes.ts, implement nodejs and browser versions
  • the browser version follows toHexString util: try String.fromCharCode api ssz#277
  • deprecate toHexString
  • tests are scanned through browser tests in this package, perf tests are included
bytes utils
    ✔ nodejs block root to RootHex using toHex                             6396520 ops/s    156.3350 ns/op        -       3868 runs  0.765 s
    ✔ nodejs block root to RootHex using toRootHex                         9505523 ops/s    105.2020 ns/op        -       6710 runs  0.812 s
    ✔ browser block root to RootHex using the deprecated toHexString       3742921 ops/s    267.1710 ns/op        -       1891 runs  0.797 s
    ✔ browser block root to RootHex using toHex                            5582008 ops/s    179.1470 ns/op        -       1690 runs  0.487 s
    ✔ browser block root to RootHex using toRootHex                        6455194 ops/s    154.9140 ns/op        -       2605 runs  0.562 s

related to ChainSafe/ssz#283

this only implement the utils, need multiple PRs to consume this work

Copy link
Contributor

github-actions bot commented Aug 29, 2024

⚠️ Performance Alert ⚠️

Possible performance regression was detected for some benchmarks.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold.

Benchmark suite Current: 0d110fa Previous: 21afb72 Ratio
isKnown normal case - 2 super set checks 655.00 ns/op 215.00 ns/op 3.05
isKnown worse case - 16 super set checks 742.00 ns/op 215.00 ns/op 3.45
Object access 1 prop 0.36400 ns/op 0.10700 ns/op 3.40
Map access 1 prop 0.33100 ns/op 0.10000 ns/op 3.31
enrSubnets - fastDeserialize 4 bits 405.00 ns/op 116.00 ns/op 3.49
getUint32 - manual 439.00 ns/op 112.00 ns/op 3.92
Full benchmark results
Benchmark suite Current: 0d110fa Previous: 21afb72 Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 2.0355 ms/op 1.7655 ms/op 1.15
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 45.461 us/op 38.773 us/op 1.17
BLS verify - blst 890.29 us/op 842.45 us/op 1.06
BLS verifyMultipleSignatures 3 - blst 1.4279 ms/op 1.2694 ms/op 1.12
BLS verifyMultipleSignatures 8 - blst 2.2637 ms/op 2.0701 ms/op 1.09
BLS verifyMultipleSignatures 32 - blst 4.8793 ms/op 4.3696 ms/op 1.12
BLS verifyMultipleSignatures 64 - blst 8.9138 ms/op 8.0967 ms/op 1.10
BLS verifyMultipleSignatures 128 - blst 16.384 ms/op 15.742 ms/op 1.04
BLS deserializing 10000 signatures 641.68 ms/op 619.29 ms/op 1.04
BLS deserializing 100000 signatures 6.3303 s/op 6.2046 s/op 1.02
BLS verifyMultipleSignatures - same message - 3 - blst 985.72 us/op 925.73 us/op 1.06
BLS verifyMultipleSignatures - same message - 8 - blst 994.64 us/op 1.0608 ms/op 0.94
BLS verifyMultipleSignatures - same message - 32 - blst 1.7247 ms/op 1.6455 ms/op 1.05
BLS verifyMultipleSignatures - same message - 64 - blst 2.5298 ms/op 2.5029 ms/op 1.01
BLS verifyMultipleSignatures - same message - 128 - blst 4.3914 ms/op 4.1014 ms/op 1.07
BLS aggregatePubkeys 32 - blst 18.120 us/op 17.538 us/op 1.03
BLS aggregatePubkeys 128 - blst 62.674 us/op 62.298 us/op 1.01
notSeenSlots=1 numMissedVotes=1 numBadVotes=10 52.495 ms/op 45.155 ms/op 1.16
notSeenSlots=1 numMissedVotes=0 numBadVotes=4 58.574 ms/op 45.053 ms/op 1.30
notSeenSlots=2 numMissedVotes=1 numBadVotes=10 28.442 ms/op 31.066 ms/op 0.92
getSlashingsAndExits - default max 71.302 us/op 64.008 us/op 1.11
getSlashingsAndExits - 2k 452.01 us/op 225.96 us/op 2.00
proposeBlockBody type=full, size=empty 5.0515 ms/op 5.3454 ms/op 0.95
isKnown best case - 1 super set check 567.00 ns/op 228.00 ns/op 2.49
isKnown normal case - 2 super set checks 655.00 ns/op 215.00 ns/op 3.05
isKnown worse case - 16 super set checks 742.00 ns/op 215.00 ns/op 3.45
InMemoryCheckpointStateCache - add get delete 3.3180 us/op 2.0790 us/op 1.60
updateUnfinalizedPubkeys - updating 10 pubkeys 842.61 us/op 564.31 us/op 1.49
updateUnfinalizedPubkeys - updating 100 pubkeys 2.2405 ms/op 2.1378 ms/op 1.05
updateUnfinalizedPubkeys - updating 1000 pubkeys 46.799 ms/op 38.645 ms/op 1.21
validate api signedAggregateAndProof - struct 1.5553 ms/op 1.8891 ms/op 0.82
validate gossip signedAggregateAndProof - struct 1.5635 ms/op 1.8800 ms/op 0.83
validate gossip attestation - vc 640000 1.0129 ms/op 946.53 us/op 1.07
batch validate gossip attestation - vc 640000 - chunk 32 125.24 us/op 118.72 us/op 1.05
batch validate gossip attestation - vc 640000 - chunk 64 119.18 us/op 103.07 us/op 1.16
batch validate gossip attestation - vc 640000 - chunk 128 110.95 us/op 94.226 us/op 1.18
batch validate gossip attestation - vc 640000 - chunk 256 96.296 us/op 92.051 us/op 1.05
pickEth1Vote - no votes 882.05 us/op 893.82 us/op 0.99
pickEth1Vote - max votes 4.5093 ms/op 5.0441 ms/op 0.89
pickEth1Vote - Eth1Data hashTreeRoot value x2048 20.867 ms/op 14.600 ms/op 1.43
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 21.495 ms/op 19.473 ms/op 1.10
pickEth1Vote - Eth1Data fastSerialize value x2048 376.47 us/op 378.39 us/op 0.99
pickEth1Vote - Eth1Data fastSerialize tree x2048 2.7298 ms/op 3.7545 ms/op 0.73
bytes32 toHexString 875.00 ns/op 345.00 ns/op 2.54
bytes32 Buffer.toString(hex) 479.00 ns/op 189.00 ns/op 2.53
bytes32 Buffer.toString(hex) from Uint8Array 645.00 ns/op 278.00 ns/op 2.32
bytes32 Buffer.toString(hex) + 0x 464.00 ns/op 188.00 ns/op 2.47
Object access 1 prop 0.36400 ns/op 0.10700 ns/op 3.40
Map access 1 prop 0.33100 ns/op 0.10000 ns/op 3.31
Object get x1000 5.2380 ns/op 5.0390 ns/op 1.04
Map get x1000 5.8940 ns/op 5.6550 ns/op 1.04
Object set x1000 29.458 ns/op 22.387 ns/op 1.32
Map set x1000 20.948 ns/op 18.426 ns/op 1.14
Return object 10000 times 0.30140 ns/op 0.27690 ns/op 1.09
Throw Error 10000 times 2.7109 us/op 2.6987 us/op 1.00
toHex 117.69 ns/op 94.482 ns/op 1.25
Buffer.from 102.66 ns/op 87.664 ns/op 1.17
shared Buffer 68.989 ns/op 60.900 ns/op 1.13
fastMsgIdFn sha256 / 200 bytes 2.1000 us/op 1.5270 us/op 1.38
fastMsgIdFn h32 xxhash / 200 bytes 482.00 ns/op 165.00 ns/op 2.92
fastMsgIdFn h64 xxhash / 200 bytes 505.00 ns/op 187.00 ns/op 2.70
fastMsgIdFn sha256 / 1000 bytes 6.8520 us/op 5.1410 us/op 1.33
fastMsgIdFn h32 xxhash / 1000 bytes 645.00 ns/op 270.00 ns/op 2.39
fastMsgIdFn h64 xxhash / 1000 bytes 596.00 ns/op 248.00 ns/op 2.40
fastMsgIdFn sha256 / 10000 bytes 52.724 us/op 43.658 us/op 1.21
fastMsgIdFn h32 xxhash / 10000 bytes 2.1580 us/op 1.4750 us/op 1.46
fastMsgIdFn h64 xxhash / 10000 bytes 1.4230 us/op 957.00 ns/op 1.49
send data - 1000 256B messages 12.220 ms/op 9.6742 ms/op 1.26
send data - 1000 512B messages 17.712 ms/op 13.129 ms/op 1.35
send data - 1000 1024B messages 24.507 ms/op 20.261 ms/op 1.21
send data - 1000 1200B messages 25.996 ms/op 22.173 ms/op 1.17
send data - 1000 2048B messages 30.068 ms/op 26.575 ms/op 1.13
send data - 1000 4096B messages 29.085 ms/op 24.949 ms/op 1.17
send data - 1000 16384B messages 70.217 ms/op 56.262 ms/op 1.25
send data - 1000 65536B messages 273.52 ms/op 164.53 ms/op 1.66
enrSubnets - fastDeserialize 64 bits 1.1540 us/op 814.00 ns/op 1.42
enrSubnets - ssz BitVector 64 bits 636.00 ns/op 268.00 ns/op 2.37
enrSubnets - fastDeserialize 4 bits 405.00 ns/op 116.00 ns/op 3.49
enrSubnets - ssz BitVector 4 bits 660.00 ns/op 270.00 ns/op 2.44
prioritizePeers score -10:0 att 32-0.1 sync 2-0 170.97 us/op 117.47 us/op 1.46
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 164.91 us/op 154.10 us/op 1.07
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 303.59 us/op 223.74 us/op 1.36
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 528.42 us/op 439.04 us/op 1.20
prioritizePeers score 0:0 att 64-1 sync 4-1 910.34 us/op 574.68 us/op 1.58
array of 16000 items push then shift 1.4156 us/op 1.2956 us/op 1.09
LinkedList of 16000 items push then shift 6.7930 ns/op 6.0880 ns/op 1.12
array of 16000 items push then pop 92.129 ns/op 78.637 ns/op 1.17
LinkedList of 16000 items push then pop 6.5470 ns/op 5.9500 ns/op 1.10
array of 24000 items push then shift 2.0266 us/op 1.9037 us/op 1.06
LinkedList of 24000 items push then shift 7.1560 ns/op 6.0160 ns/op 1.19
array of 24000 items push then pop 158.27 ns/op 105.13 ns/op 1.51
LinkedList of 24000 items push then pop 6.6660 ns/op 5.8560 ns/op 1.14
intersect bitArray bitLen 8 5.8390 ns/op 5.2330 ns/op 1.12
intersect array and set length 8 42.315 ns/op 37.804 ns/op 1.12
intersect bitArray bitLen 128 27.665 ns/op 26.340 ns/op 1.05
intersect array and set length 128 611.84 ns/op 576.58 ns/op 1.06
bitArray.getTrueBitIndexes() bitLen 128 2.6910 us/op 1.9600 us/op 1.37
bitArray.getTrueBitIndexes() bitLen 248 3.3670 us/op 3.2810 us/op 1.03
bitArray.getTrueBitIndexes() bitLen 512 7.7880 us/op 6.4010 us/op 1.22
Buffer.concat 32 items 1.0590 us/op 796.00 ns/op 1.33
Uint8Array.set 32 items 1.5510 us/op 1.7410 us/op 0.89
Buffer.copy 1.6410 us/op 2.0440 us/op 0.80
Uint8Array.set - with subarray 2.0140 us/op 2.2720 us/op 0.89
Uint8Array.set - without subarray 1.4520 us/op 1.4010 us/op 1.04
getUint32 - dataview 462.00 ns/op 169.00 ns/op 2.73
getUint32 - manual 439.00 ns/op 112.00 ns/op 3.92
Set add up to 64 items then delete first 1.9010 us/op 1.7566 us/op 1.08
OrderedSet add up to 64 items then delete first 2.9393 us/op 2.7040 us/op 1.09
Set add up to 64 items then delete last 2.0882 us/op 2.0801 us/op 1.00
OrderedSet add up to 64 items then delete last 3.2535 us/op 2.6716 us/op 1.22
Set add up to 64 items then delete middle 2.1072 us/op 1.8286 us/op 1.15
OrderedSet add up to 64 items then delete middle 4.7293 us/op 3.9290 us/op 1.20
Set add up to 128 items then delete first 4.1100 us/op 3.4960 us/op 1.18
OrderedSet add up to 128 items then delete first 6.1479 us/op 5.4790 us/op 1.12
Set add up to 128 items then delete last 4.1684 us/op 3.4010 us/op 1.23
OrderedSet add up to 128 items then delete last 6.5595 us/op 5.1321 us/op 1.28
Set add up to 128 items then delete middle 4.2020 us/op 3.4089 us/op 1.23
OrderedSet add up to 128 items then delete middle 12.362 us/op 10.483 us/op 1.18
Set add up to 256 items then delete first 8.5974 us/op 6.8948 us/op 1.25
OrderedSet add up to 256 items then delete first 13.012 us/op 11.019 us/op 1.18
Set add up to 256 items then delete last 8.8077 us/op 6.7490 us/op 1.31
OrderedSet add up to 256 items then delete last 15.313 us/op 10.398 us/op 1.47
Set add up to 256 items then delete middle 8.6271 us/op 6.7092 us/op 1.29
OrderedSet add up to 256 items then delete middle 36.608 us/op 30.617 us/op 1.20
transfer serialized Status (84 B) 1.6190 us/op 1.1440 us/op 1.42
copy serialized Status (84 B) 1.5660 us/op 993.00 ns/op 1.58
transfer serialized SignedVoluntaryExit (112 B) 1.6580 us/op 1.4790 us/op 1.12
copy serialized SignedVoluntaryExit (112 B) 1.4230 us/op 1.1190 us/op 1.27
transfer serialized ProposerSlashing (416 B) 1.5840 us/op 1.7200 us/op 0.92
copy serialized ProposerSlashing (416 B) 2.1700 us/op 1.9030 us/op 1.14
transfer serialized Attestation (485 B) 2.1460 us/op 1.5240 us/op 1.41
copy serialized Attestation (485 B) 2.1440 us/op 1.7810 us/op 1.20
transfer serialized AttesterSlashing (33232 B) 1.8340 us/op 2.5410 us/op 0.72
copy serialized AttesterSlashing (33232 B) 4.8920 us/op 4.2170 us/op 1.16
transfer serialized Small SignedBeaconBlock (128000 B) 2.7960 us/op 2.7390 us/op 1.02
copy serialized Small SignedBeaconBlock (128000 B) 10.405 us/op 12.335 us/op 0.84
transfer serialized Avg SignedBeaconBlock (200000 B) 3.0700 us/op 2.3550 us/op 1.30
copy serialized Avg SignedBeaconBlock (200000 B) 13.978 us/op 11.834 us/op 1.18
transfer serialized BlobsSidecar (524380 B) 3.6760 us/op 2.2380 us/op 1.64
copy serialized BlobsSidecar (524380 B) 118.96 us/op 68.986 us/op 1.72
transfer serialized Big SignedBeaconBlock (1000000 B) 3.0710 us/op 2.5990 us/op 1.18
copy serialized Big SignedBeaconBlock (1000000 B) 193.60 us/op 137.20 us/op 1.41
pass gossip attestations to forkchoice per slot 2.5161 ms/op 2.4335 ms/op 1.03
forkChoice updateHead vc 100000 bc 64 eq 0 422.75 us/op 493.01 us/op 0.86
forkChoice updateHead vc 600000 bc 64 eq 0 2.5096 ms/op 2.4397 ms/op 1.03
forkChoice updateHead vc 1000000 bc 64 eq 0 4.1320 ms/op 4.2162 ms/op 0.98
forkChoice updateHead vc 600000 bc 320 eq 0 2.4655 ms/op 2.5426 ms/op 0.97
forkChoice updateHead vc 600000 bc 1200 eq 0 2.5988 ms/op 3.1266 ms/op 0.83
forkChoice updateHead vc 600000 bc 7200 eq 0 3.2987 ms/op 2.8391 ms/op 1.16
forkChoice updateHead vc 600000 bc 64 eq 1000 9.6789 ms/op 8.8821 ms/op 1.09
forkChoice updateHead vc 600000 bc 64 eq 10000 9.3317 ms/op 9.5579 ms/op 0.98
forkChoice updateHead vc 600000 bc 64 eq 300000 12.504 ms/op 11.684 ms/op 1.07
computeDeltas 500000 validators 300 proto nodes 2.9856 ms/op 2.9960 ms/op 1.00
computeDeltas 500000 validators 1200 proto nodes 2.9660 ms/op 3.0738 ms/op 0.96
computeDeltas 500000 validators 7200 proto nodes 3.0473 ms/op 2.9491 ms/op 1.03
computeDeltas 750000 validators 300 proto nodes 4.7256 ms/op 4.4889 ms/op 1.05
computeDeltas 750000 validators 1200 proto nodes 4.3579 ms/op 4.3873 ms/op 0.99
computeDeltas 750000 validators 7200 proto nodes 4.2524 ms/op 4.3908 ms/op 0.97
computeDeltas 1400000 validators 300 proto nodes 8.6163 ms/op 8.0745 ms/op 1.07
computeDeltas 1400000 validators 1200 proto nodes 8.3762 ms/op 8.1693 ms/op 1.03
computeDeltas 1400000 validators 7200 proto nodes 8.3168 ms/op 8.0097 ms/op 1.04
computeDeltas 2100000 validators 300 proto nodes 12.529 ms/op 12.190 ms/op 1.03
computeDeltas 2100000 validators 1200 proto nodes 12.504 ms/op 12.008 ms/op 1.04
computeDeltas 2100000 validators 7200 proto nodes 12.223 ms/op 12.214 ms/op 1.00
altair processAttestation - 250000 vs - 7PWei normalcase 1.4510 ms/op 1.3669 ms/op 1.06
altair processAttestation - 250000 vs - 7PWei worstcase 2.2884 ms/op 2.0237 ms/op 1.13
altair processAttestation - setStatus - 1/6 committees join 72.387 us/op 58.187 us/op 1.24
altair processAttestation - setStatus - 1/3 committees join 130.92 us/op 111.60 us/op 1.17
altair processAttestation - setStatus - 1/2 committees join 198.83 us/op 166.59 us/op 1.19
altair processAttestation - setStatus - 2/3 committees join 260.75 us/op 216.88 us/op 1.20
altair processAttestation - setStatus - 4/5 committees join 415.05 us/op 344.31 us/op 1.21
altair processAttestation - setStatus - 100% committees join 481.54 us/op 416.78 us/op 1.16
altair processBlock - 250000 vs - 7PWei normalcase 5.0412 ms/op 4.0658 ms/op 1.24
altair processBlock - 250000 vs - 7PWei normalcase hashState 26.946 ms/op 25.434 ms/op 1.06
altair processBlock - 250000 vs - 7PWei worstcase 35.991 ms/op 37.526 ms/op 0.96
altair processBlock - 250000 vs - 7PWei worstcase hashState 73.887 ms/op 73.195 ms/op 1.01
phase0 processBlock - 250000 vs - 7PWei normalcase 1.8327 ms/op 1.9371 ms/op 0.95
phase0 processBlock - 250000 vs - 7PWei worstcase 24.487 ms/op 22.379 ms/op 1.09
altair processEth1Data - 250000 vs - 7PWei normalcase 262.65 us/op 229.75 us/op 1.14
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 7.0440 us/op 5.4440 us/op 1.29
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 36.030 us/op 33.978 us/op 1.06
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 11.291 us/op 8.7480 us/op 1.29
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 6.7630 us/op 6.0420 us/op 1.12
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 151.20 us/op 143.88 us/op 1.05
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 1.0024 ms/op 876.22 us/op 1.14
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 1.3747 ms/op 1.3389 ms/op 1.03
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 1.4248 ms/op 1.3691 ms/op 1.04
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 3.9591 ms/op 2.6302 ms/op 1.51
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 1.4011 ms/op 1.3973 ms/op 1.00
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 3.3066 ms/op 3.0644 ms/op 1.08
Tree 40 250000 create 238.75 ms/op 188.32 ms/op 1.27
Tree 40 250000 get(125000) 132.13 ns/op 112.94 ns/op 1.17
Tree 40 250000 set(125000) 563.73 ns/op 512.97 ns/op 1.10
Tree 40 250000 toArray() 19.921 ms/op 9.6627 ms/op 2.06
Tree 40 250000 iterate all - toArray() + loop 18.570 ms/op 9.6478 ms/op 1.92
Tree 40 250000 iterate all - get(i) 52.630 ms/op 38.873 ms/op 1.35
Array 250000 create 2.7587 ms/op 2.2916 ms/op 1.20
Array 250000 clone - spread 1.5389 ms/op 1.1744 ms/op 1.31
Array 250000 get(125000) 0.65100 ns/op 0.37400 ns/op 1.74
Array 250000 set(125000) 0.62000 ns/op 0.38200 ns/op 1.62
Array 250000 iterate all - loop 81.261 us/op 76.145 us/op 1.07
phase0 afterProcessEpoch - 250000 vs - 7PWei 83.885 ms/op 75.940 ms/op 1.10
Array.fill - length 1000000 2.7936 ms/op 2.4840 ms/op 1.12
Array push - length 1000000 15.542 ms/op 13.893 ms/op 1.12
Array.get 0.29741 ns/op 0.23831 ns/op 1.25
Uint8Array.get 0.36321 ns/op 0.30729 ns/op 1.18
phase0 beforeProcessEpoch - 250000 vs - 7PWei 20.400 ms/op 14.863 ms/op 1.37
altair processEpoch - mainnet_e81889 329.82 ms/op 316.11 ms/op 1.04
mainnet_e81889 - altair beforeProcessEpoch 18.414 ms/op 15.908 ms/op 1.16
mainnet_e81889 - altair processJustificationAndFinalization 12.844 us/op 10.022 us/op 1.28
mainnet_e81889 - altair processInactivityUpdates 4.1866 ms/op 4.0255 ms/op 1.04
mainnet_e81889 - altair processRewardsAndPenalties 50.234 ms/op 52.940 ms/op 0.95
mainnet_e81889 - altair processRegistryUpdates 1.9910 us/op 1.3490 us/op 1.48
mainnet_e81889 - altair processSlashings 869.00 ns/op 375.00 ns/op 2.32
mainnet_e81889 - altair processEth1DataReset 722.00 ns/op 319.00 ns/op 2.26
mainnet_e81889 - altair processEffectiveBalanceUpdates 1.1955 ms/op 1.4875 ms/op 0.80
mainnet_e81889 - altair processSlashingsReset 3.6860 us/op 1.0450 us/op 3.53
mainnet_e81889 - altair processRandaoMixesReset 8.5380 us/op 2.1130 us/op 4.04
mainnet_e81889 - altair processHistoricalRootsUpdate 855.00 ns/op 238.00 ns/op 3.59
mainnet_e81889 - altair processParticipationFlagUpdates 3.2110 us/op 900.00 ns/op 3.57
mainnet_e81889 - altair processSyncCommitteeUpdates 1.0470 us/op 211.00 ns/op 4.96
mainnet_e81889 - altair afterProcessEpoch 85.872 ms/op 79.320 ms/op 1.08
capella processEpoch - mainnet_e217614 1.3039 s/op 1.0768 s/op 1.21
mainnet_e217614 - capella beforeProcessEpoch 67.533 ms/op 74.585 ms/op 0.91
mainnet_e217614 - capella processJustificationAndFinalization 17.711 us/op 11.859 us/op 1.49
mainnet_e217614 - capella processInactivityUpdates 13.913 ms/op 14.360 ms/op 0.97
mainnet_e217614 - capella processRewardsAndPenalties 259.34 ms/op 251.28 ms/op 1.03
mainnet_e217614 - capella processRegistryUpdates 17.474 us/op 11.281 us/op 1.55
mainnet_e217614 - capella processSlashings 1.4550 us/op 396.00 ns/op 3.67
mainnet_e217614 - capella processEth1DataReset 1.0930 us/op 321.00 ns/op 3.40
mainnet_e217614 - capella processEffectiveBalanceUpdates 16.006 ms/op 12.405 ms/op 1.29
mainnet_e217614 - capella processSlashingsReset 5.9370 us/op 1.9560 us/op 3.04
mainnet_e217614 - capella processRandaoMixesReset 8.4150 us/op 5.8810 us/op 1.43
mainnet_e217614 - capella processHistoricalRootsUpdate 2.1230 us/op 313.00 ns/op 6.78
mainnet_e217614 - capella processParticipationFlagUpdates 3.0530 us/op 1.0040 us/op 3.04
mainnet_e217614 - capella afterProcessEpoch 221.27 ms/op 200.04 ms/op 1.11
phase0 processEpoch - mainnet_e58758 402.42 ms/op 388.84 ms/op 1.03
mainnet_e58758 - phase0 beforeProcessEpoch 91.692 ms/op 77.377 ms/op 1.19
mainnet_e58758 - phase0 processJustificationAndFinalization 19.479 us/op 13.432 us/op 1.45
mainnet_e58758 - phase0 processRewardsAndPenalties 28.021 ms/op 29.953 ms/op 0.94
mainnet_e58758 - phase0 processRegistryUpdates 5.5090 us/op 6.6010 us/op 0.83
mainnet_e58758 - phase0 processSlashings 688.00 ns/op 424.00 ns/op 1.62
mainnet_e58758 - phase0 processEth1DataReset 801.00 ns/op 247.00 ns/op 3.24
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 891.11 us/op 1.3599 ms/op 0.66
mainnet_e58758 - phase0 processSlashingsReset 3.6430 us/op 1.7700 us/op 2.06
mainnet_e58758 - phase0 processRandaoMixesReset 7.5560 us/op 2.1380 us/op 3.53
mainnet_e58758 - phase0 processHistoricalRootsUpdate 891.00 ns/op 254.00 ns/op 3.51
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.7100 us/op 2.5140 us/op 1.87
mainnet_e58758 - phase0 afterProcessEpoch 71.009 ms/op 62.627 ms/op 1.13
phase0 processEffectiveBalanceUpdates - 250000 normalcase 1.1062 ms/op 1.0438 ms/op 1.06
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.4734 ms/op 1.5435 ms/op 0.95
altair processInactivityUpdates - 250000 normalcase 18.743 ms/op 19.725 ms/op 0.95
altair processInactivityUpdates - 250000 worstcase 15.656 ms/op 18.338 ms/op 0.85
phase0 processRegistryUpdates - 250000 normalcase 5.5190 us/op 2.8220 us/op 1.96
phase0 processRegistryUpdates - 250000 badcase_full_deposits 319.70 us/op 185.20 us/op 1.73
phase0 processRegistryUpdates - 250000 worstcase 0.5 117.81 ms/op 114.78 ms/op 1.03
altair processRewardsAndPenalties - 250000 normalcase 41.666 ms/op 44.824 ms/op 0.93
altair processRewardsAndPenalties - 250000 worstcase 43.700 ms/op 39.060 ms/op 1.12
phase0 getAttestationDeltas - 250000 normalcase 8.6253 ms/op 5.5106 ms/op 1.57
phase0 getAttestationDeltas - 250000 worstcase 8.2364 ms/op 6.4599 ms/op 1.27
phase0 processSlashings - 250000 worstcase 88.064 us/op 85.758 us/op 1.03
altair processSyncCommitteeUpdates - 250000 111.03 ms/op 105.88 ms/op 1.05
BeaconState.hashTreeRoot - No change 579.00 ns/op 211.00 ns/op 2.74
BeaconState.hashTreeRoot - 1 full validator 140.05 us/op 127.19 us/op 1.10
BeaconState.hashTreeRoot - 32 full validator 897.84 us/op 1.5365 ms/op 0.58
BeaconState.hashTreeRoot - 512 full validator 15.913 ms/op 15.801 ms/op 1.01
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 151.41 us/op 153.17 us/op 0.99
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 2.2049 ms/op 1.8542 ms/op 1.19
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 30.220 ms/op 27.309 ms/op 1.11
BeaconState.hashTreeRoot - 1 balances 125.67 us/op 123.78 us/op 1.02
BeaconState.hashTreeRoot - 32 balances 1.5058 ms/op 1.3085 ms/op 1.15
BeaconState.hashTreeRoot - 512 balances 11.212 ms/op 11.505 ms/op 0.97
BeaconState.hashTreeRoot - 250000 balances 238.66 ms/op 158.85 ms/op 1.50
aggregationBits - 2048 els - zipIndexesInBitList 34.895 us/op 18.532 us/op 1.88
byteArrayEquals 32 48.289 ns/op 46.923 ns/op 1.03
Buffer.compare 32 16.050 ns/op 15.335 ns/op 1.05
byteArrayEquals 1024 1.3111 us/op 1.2542 us/op 1.05
Buffer.compare 1024 24.876 ns/op 23.068 ns/op 1.08
byteArrayEquals 16384 21.138 us/op 19.890 us/op 1.06
Buffer.compare 16384 190.32 ns/op 194.65 ns/op 0.98
byteArrayEquals 123687377 156.70 ms/op 150.25 ms/op 1.04
Buffer.compare 123687377 6.1568 ms/op 3.6677 ms/op 1.68
byteArrayEquals 32 - diff last byte 47.338 ns/op 46.804 ns/op 1.01
Buffer.compare 32 - diff last byte 16.121 ns/op 15.936 ns/op 1.01
byteArrayEquals 1024 - diff last byte 1.3224 us/op 1.2493 us/op 1.06
Buffer.compare 1024 - diff last byte 26.710 ns/op 24.006 ns/op 1.11
byteArrayEquals 16384 - diff last byte 22.194 us/op 19.862 us/op 1.12
Buffer.compare 16384 - diff last byte 206.99 ns/op 176.51 ns/op 1.17
byteArrayEquals 123687377 - diff last byte 153.92 ms/op 140.90 ms/op 1.09
Buffer.compare 123687377 - diff last byte 6.0769 ms/op 5.3437 ms/op 1.14
byteArrayEquals 32 - random bytes 4.8310 ns/op 4.3790 ns/op 1.10
Buffer.compare 32 - random bytes 15.496 ns/op 14.270 ns/op 1.09
byteArrayEquals 1024 - random bytes 4.8820 ns/op 4.3420 ns/op 1.12
Buffer.compare 1024 - random bytes 15.224 ns/op 14.467 ns/op 1.05
byteArrayEquals 16384 - random bytes 4.8670 ns/op 4.3280 ns/op 1.12
Buffer.compare 16384 - random bytes 15.440 ns/op 13.957 ns/op 1.11
byteArrayEquals 123687377 - random bytes 7.6800 ns/op 5.2200 ns/op 1.47
Buffer.compare 123687377 - random bytes 18.310 ns/op 14.870 ns/op 1.23
regular array get 100000 times 30.845 us/op 28.041 us/op 1.10
wrappedArray get 100000 times 30.970 us/op 28.069 us/op 1.10
arrayWithProxy get 100000 times 9.7121 ms/op 9.0282 ms/op 1.08
ssz.Root.equals 44.050 ns/op 40.615 ns/op 1.08
byteArrayEquals 42.925 ns/op 39.826 ns/op 1.08
Buffer.compare 8.8340 ns/op 8.1280 ns/op 1.09
shuffle list - 16384 els 5.5684 ms/op 4.9683 ms/op 1.12
shuffle list - 250000 els 81.985 ms/op 73.424 ms/op 1.12
processSlot - 1 slots 12.682 us/op 12.192 us/op 1.04
processSlot - 32 slots 2.5787 ms/op 3.6279 ms/op 0.71
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 37.644 ms/op 43.537 ms/op 0.86
getCommitteeAssignments - req 1 vs - 250000 vc 1.7818 ms/op 1.8008 ms/op 0.99
getCommitteeAssignments - req 100 vs - 250000 vc 3.5889 ms/op 3.5057 ms/op 1.02
getCommitteeAssignments - req 1000 vs - 250000 vc 3.8594 ms/op 3.7704 ms/op 1.02
findModifiedValidators - 10000 modified validators 254.08 ms/op 224.17 ms/op 1.13
findModifiedValidators - 1000 modified validators 164.97 ms/op 137.47 ms/op 1.20
findModifiedValidators - 100 modified validators 166.15 ms/op 134.39 ms/op 1.24
findModifiedValidators - 10 modified validators 167.30 ms/op 126.17 ms/op 1.33
findModifiedValidators - 1 modified validators 178.41 ms/op 120.35 ms/op 1.48
findModifiedValidators - no difference 184.46 ms/op 136.94 ms/op 1.35
compare ViewDUs 3.7677 s/op 2.9474 s/op 1.28
compare each validator Uint8Array 1.8333 s/op 1.7321 s/op 1.06
compare ViewDU to Uint8Array 1.1382 s/op 734.24 ms/op 1.55
migrate state 1000000 validators, 24 modified, 0 new 650.13 ms/op 601.34 ms/op 1.08
migrate state 1000000 validators, 1700 modified, 1000 new 879.97 ms/op 856.82 ms/op 1.03
migrate state 1000000 validators, 3400 modified, 2000 new 1.1092 s/op 1.0524 s/op 1.05
migrate state 1500000 validators, 24 modified, 0 new 669.39 ms/op 602.63 ms/op 1.11
migrate state 1500000 validators, 1700 modified, 1000 new 894.81 ms/op 860.33 ms/op 1.04
migrate state 1500000 validators, 3400 modified, 2000 new 1.0788 s/op 1.0565 s/op 1.02
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 6.4500 ns/op 3.5300 ns/op 1.83
state getBlockRootAtSlot - 250000 vs - 7PWei 466.58 ns/op 850.73 ns/op 0.55
computeProposers - vc 250000 5.9497 ms/op 6.4893 ms/op 0.92
computeEpochShuffling - vc 250000 82.639 ms/op 79.458 ms/op 1.04
getNextSyncCommittee - vc 250000 99.900 ms/op 106.70 ms/op 0.94
computeSigningRoot for AttestationData 18.170 us/op 20.726 us/op 0.88
hash AttestationData serialized data then Buffer.toString(base64) 1.2435 us/op 1.1666 us/op 1.07
toHexString serialized data 759.28 ns/op 796.82 ns/op 0.95
Buffer.toString(base64) 132.95 ns/op 141.75 ns/op 0.94
nodejs block root to RootHex using toHex 117.43 ns/op
nodejs block root to RootHex using toRootHex 76.362 ns/op
browser block root to RootHex using the deprecated toHexString 202.46 ns/op
browser block root to RootHex using toHex 162.36 ns/op
browser block root to RootHex using toRootHex 158.68 ns/op

by benchmarkbot/action

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 41.97531% with 47 lines in your changes missing coverage. Please review.

Project coverage is 49.35%. Comparing base (a7286bd) to head (7f39d7f).
Report is 2 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #7060      +/-   ##
============================================
- Coverage     49.37%   49.35%   -0.02%     
============================================
  Files           589      592       +3     
  Lines         39233    39293      +60     
  Branches       2246     2248       +2     
============================================
+ Hits          19370    19392      +22     
- Misses        19822    19860      +38     
  Partials         41       41              

@twoeths twoeths marked this pull request as ready for review August 29, 2024 08:09
@twoeths twoeths requested a review from a team as a code owner August 29, 2024 08:09
return String.fromCharCode(...rootCharCodes);
}

export function fromHex(hex: string): Uint8Array {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

}

// Shared buffer to convert root to hex
let rootBuf: Buffer | undefined;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

nflaig
nflaig previously approved these changes Aug 29, 2024
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.

LGTM - we might be able to not load nodejs files at all in browser environments but this PR already nicely separates the implementations

packages/utils/src/bytes.ts Outdated Show resolved Hide resolved
Co-authored-by: Nico Flaig <nflaig@protonmail.com>
@wemeetagain wemeetagain merged commit 19ac678 into unstable Aug 30, 2024
19 of 20 checks passed
@wemeetagain wemeetagain deleted the te/isomorphic_utils branch August 30, 2024 12:22
philknows pushed a commit that referenced this pull request Sep 3, 2024
* feat: implement isomorphic utils for nodes and browser

* fix: avoid async import

* chore: revise toHexString() comment as in PR review

Co-authored-by: Nico Flaig <nflaig@protonmail.com>

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
@wemeetagain
Copy link
Member

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