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

fix: reuse Buffer instance #7016

Merged
merged 7 commits into from
Aug 13, 2024
Merged

fix: reuse Buffer instance #7016

merged 7 commits into from
Aug 13, 2024

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Aug 13, 2024

Motivation

  • For some flows, we allocating Buffer instances with Buffer.from() and then convert to hex/base64. We can just reuse same Buffer in that case that would help the gc a lot

Description

  • Improve msgIdToStrFn() function by using the same Buffer
  • New toRootHex() function using the same Buffer instance to compute RootHex from a Root
  • use the same Buffer for each function in sszBytes util, for example to extract AttData base64
  • Benchmarks showed 1.5x faster but I think the most benefit is saving memory allocation which helps the gc

Copy link
Contributor

github-actions bot commented Aug 13, 2024

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 511718b Previous: 64fe1db Ratio
getPubkeys - index2pubkey - req 1000 vs - 250000 vc 1.8063 ms/op 1.8003 ms/op 1.00
getPubkeys - validatorsArr - req 1000 vs - 250000 vc 38.970 us/op 62.923 us/op 0.62
BLS verify - blst 878.52 us/op 856.31 us/op 1.03
BLS verifyMultipleSignatures 3 - blst 1.3549 ms/op 1.3452 ms/op 1.01
BLS verifyMultipleSignatures 8 - blst 1.9876 ms/op 2.1245 ms/op 0.94
BLS verifyMultipleSignatures 32 - blst 4.4026 ms/op 4.6889 ms/op 0.94
BLS verifyMultipleSignatures 64 - blst 8.5794 ms/op 8.5742 ms/op 1.00
BLS verifyMultipleSignatures 128 - blst 16.782 ms/op 16.264 ms/op 1.03
BLS deserializing 10000 signatures 621.88 ms/op 636.46 ms/op 0.98
BLS deserializing 100000 signatures 6.2145 s/op 6.3021 s/op 0.99
BLS verifyMultipleSignatures - same message - 3 - blst 1.0191 ms/op 1.0099 ms/op 1.01
BLS verifyMultipleSignatures - same message - 8 - blst 1.0777 ms/op 1.0873 ms/op 0.99
BLS verifyMultipleSignatures - same message - 32 - blst 1.6709 ms/op 1.7250 ms/op 0.97
BLS verifyMultipleSignatures - same message - 64 - blst 2.4826 ms/op 2.5609 ms/op 0.97
BLS verifyMultipleSignatures - same message - 128 - blst 3.9744 ms/op 4.1836 ms/op 0.95
BLS aggregatePubkeys 32 - blst 17.648 us/op 18.196 us/op 0.97
BLS aggregatePubkeys 128 - blst 61.379 us/op 64.035 us/op 0.96
notSeenSlots=1 numMissedVotes=1 numBadVotes=10 67.966 ms/op 65.789 ms/op 1.03
notSeenSlots=1 numMissedVotes=0 numBadVotes=4 44.402 ms/op 47.840 ms/op 0.93
notSeenSlots=2 numMissedVotes=1 numBadVotes=10 30.711 ms/op 32.076 ms/op 0.96
getSlashingsAndExits - default max 67.874 us/op 69.649 us/op 0.97
getSlashingsAndExits - 2k 236.38 us/op 263.28 us/op 0.90
proposeBlockBody type=full, size=empty 5.1628 ms/op 5.2151 ms/op 0.99
isKnown best case - 1 super set check 428.00 ns/op 492.00 ns/op 0.87
isKnown normal case - 2 super set checks 432.00 ns/op 495.00 ns/op 0.87
isKnown worse case - 16 super set checks 446.00 ns/op 474.00 ns/op 0.94
InMemoryCheckpointStateCache - add get delete 2.6400 us/op 4.5260 us/op 0.58
validate api signedAggregateAndProof - struct 2.0048 ms/op 1.7464 ms/op 1.15
validate gossip signedAggregateAndProof - struct 1.4953 ms/op 1.5010 ms/op 1.00
validate gossip attestation - vc 640000 982.59 us/op 1.0377 ms/op 0.95
batch validate gossip attestation - vc 640000 - chunk 32 123.89 us/op 132.93 us/op 0.93
batch validate gossip attestation - vc 640000 - chunk 64 105.42 us/op 114.51 us/op 0.92
batch validate gossip attestation - vc 640000 - chunk 128 96.230 us/op 112.24 us/op 0.86
batch validate gossip attestation - vc 640000 - chunk 256 91.860 us/op 111.62 us/op 0.82
pickEth1Vote - no votes 783.08 us/op 1.0398 ms/op 0.75
pickEth1Vote - max votes 7.0273 ms/op 11.599 ms/op 0.61
pickEth1Vote - Eth1Data hashTreeRoot value x2048 15.561 ms/op 20.416 ms/op 0.76
pickEth1Vote - Eth1Data hashTreeRoot tree x2048 18.742 ms/op 22.145 ms/op 0.85
pickEth1Vote - Eth1Data fastSerialize value x2048 330.23 us/op 597.66 us/op 0.55
pickEth1Vote - Eth1Data fastSerialize tree x2048 4.4541 ms/op 4.4597 ms/op 1.00
bytes32 toHexString 520.00 ns/op 840.00 ns/op 0.62
bytes32 Buffer.toString(hex) 434.00 ns/op 494.00 ns/op 0.88
bytes32 Buffer.toString(hex) from Uint8Array 517.00 ns/op 591.00 ns/op 0.87
bytes32 Buffer.toString(hex) + 0x 481.00 ns/op 479.00 ns/op 1.00
Object access 1 prop 0.30400 ns/op 0.36000 ns/op 0.84
Map access 1 prop 0.29600 ns/op 0.38100 ns/op 0.78
Object get x1000 4.5810 ns/op 5.2660 ns/op 0.87
Map get x1000 5.3470 ns/op 5.9960 ns/op 0.89
Object set x1000 24.302 ns/op 30.727 ns/op 0.79
Map set x1000 17.601 ns/op 26.693 ns/op 0.66
Return object 10000 times 0.26800 ns/op 0.32890 ns/op 0.81
Throw Error 10000 times 2.4077 us/op 3.1036 us/op 0.78
toHex 102.81 ns/op
Buffer.from 88.889 ns/op
shared Buffer 60.121 ns/op
fastMsgIdFn sha256 / 200 bytes 1.7870 us/op 2.1860 us/op 0.82
fastMsgIdFn h32 xxhash / 200 bytes 383.00 ns/op 527.00 ns/op 0.73
fastMsgIdFn h64 xxhash / 200 bytes 418.00 ns/op 509.00 ns/op 0.82
fastMsgIdFn sha256 / 1000 bytes 5.3440 us/op 6.3000 us/op 0.85
fastMsgIdFn h32 xxhash / 1000 bytes 499.00 ns/op 654.00 ns/op 0.76
fastMsgIdFn h64 xxhash / 1000 bytes 484.00 ns/op 570.00 ns/op 0.85
fastMsgIdFn sha256 / 10000 bytes 44.593 us/op 52.322 us/op 0.85
fastMsgIdFn h32 xxhash / 10000 bytes 1.7550 us/op 2.0890 us/op 0.84
fastMsgIdFn h64 xxhash / 10000 bytes 1.2380 us/op 1.3170 us/op 0.94
send data - 1000 256B messages 9.7255 ms/op 12.966 ms/op 0.75
send data - 1000 512B messages 14.920 ms/op 19.483 ms/op 0.77
send data - 1000 1024B messages 22.149 ms/op 25.797 ms/op 0.86
send data - 1000 1200B messages 24.951 ms/op 25.429 ms/op 0.98
send data - 1000 2048B messages 28.356 ms/op 37.352 ms/op 0.76
send data - 1000 4096B messages 25.975 ms/op 33.505 ms/op 0.78
send data - 1000 16384B messages 69.730 ms/op 68.949 ms/op 1.01
send data - 1000 65536B messages 246.74 ms/op 286.88 ms/op 0.86
enrSubnets - fastDeserialize 64 bits 1.0750 us/op 1.2740 us/op 0.84
enrSubnets - ssz BitVector 64 bits 497.00 ns/op 631.00 ns/op 0.79
enrSubnets - fastDeserialize 4 bits 312.00 ns/op 383.00 ns/op 0.81
enrSubnets - ssz BitVector 4 bits 501.00 ns/op 630.00 ns/op 0.80
prioritizePeers score -10:0 att 32-0.1 sync 2-0 124.69 us/op 118.18 us/op 1.06
prioritizePeers score 0:0 att 32-0.25 sync 2-0.25 135.58 us/op 131.81 us/op 1.03
prioritizePeers score 0:0 att 32-0.5 sync 2-0.5 260.92 us/op 232.95 us/op 1.12
prioritizePeers score 0:0 att 64-0.75 sync 4-0.75 422.50 us/op 505.56 us/op 0.84
prioritizePeers score 0:0 att 64-1 sync 4-1 712.10 us/op 739.96 us/op 0.96
array of 16000 items push then shift 1.2521 us/op 1.4520 us/op 0.86
LinkedList of 16000 items push then shift 7.2360 ns/op 6.8030 ns/op 1.06
array of 16000 items push then pop 101.42 ns/op 120.13 ns/op 0.84
LinkedList of 16000 items push then pop 6.1470 ns/op 6.3790 ns/op 0.96
array of 24000 items push then shift 1.7415 us/op 1.9434 us/op 0.90
LinkedList of 24000 items push then shift 6.7830 ns/op 6.9240 ns/op 0.98
array of 24000 items push then pop 115.23 ns/op 132.65 ns/op 0.87
LinkedList of 24000 items push then pop 6.2410 ns/op 6.4250 ns/op 0.97
intersect bitArray bitLen 8 5.3910 ns/op 5.6920 ns/op 0.95
intersect array and set length 8 38.131 ns/op 42.036 ns/op 0.91
intersect bitArray bitLen 128 25.260 ns/op 26.879 ns/op 0.94
intersect array and set length 128 555.86 ns/op 607.83 ns/op 0.91
bitArray.getTrueBitIndexes() bitLen 128 2.2010 us/op 2.4000 us/op 0.92
bitArray.getTrueBitIndexes() bitLen 248 3.7160 us/op 3.5530 us/op 1.05
bitArray.getTrueBitIndexes() bitLen 512 8.1230 us/op 8.8160 us/op 0.92
Buffer.concat 32 items 957.00 ns/op 1.1880 us/op 0.81
Uint8Array.set 32 items 1.3340 us/op 1.7700 us/op 0.75
Buffer.copy 1.4860 us/op 2.3830 us/op 0.62
Uint8Array.set - with subarray 1.7790 us/op 3.2580 us/op 0.55
Uint8Array.set - without subarray 1.2600 us/op 1.9690 us/op 0.64
getUint32 - dataview 399.00 ns/op 515.00 ns/op 0.77
getUint32 - manual 318.00 ns/op 416.00 ns/op 0.76
Set add up to 64 items then delete first 1.6529 us/op 1.8459 us/op 0.90
OrderedSet add up to 64 items then delete first 2.5699 us/op 2.9095 us/op 0.88
Set add up to 64 items then delete last 1.9121 us/op 2.0943 us/op 0.91
OrderedSet add up to 64 items then delete last 2.9640 us/op 3.1956 us/op 0.93
Set add up to 64 items then delete middle 1.8994 us/op 2.0910 us/op 0.91
OrderedSet add up to 64 items then delete middle 4.2278 us/op 4.6970 us/op 0.90
Set add up to 128 items then delete first 3.6551 us/op 4.2091 us/op 0.87
OrderedSet add up to 128 items then delete first 5.6154 us/op 6.4835 us/op 0.87
Set add up to 128 items then delete last 3.7207 us/op 4.1051 us/op 0.91
OrderedSet add up to 128 items then delete last 5.7106 us/op 6.1582 us/op 0.93
Set add up to 128 items then delete middle 3.6243 us/op 4.0013 us/op 0.91
OrderedSet add up to 128 items then delete middle 11.189 us/op 11.806 us/op 0.95
Set add up to 256 items then delete first 7.0485 us/op 8.0984 us/op 0.87
OrderedSet add up to 256 items then delete first 10.881 us/op 12.644 us/op 0.86
Set add up to 256 items then delete last 7.0213 us/op 7.8239 us/op 0.90
OrderedSet add up to 256 items then delete last 11.296 us/op 12.012 us/op 0.94
Set add up to 256 items then delete middle 6.9871 us/op 7.8280 us/op 0.89
OrderedSet add up to 256 items then delete middle 31.807 us/op 34.473 us/op 0.92
transfer serialized Status (84 B) 1.2980 us/op 1.3820 us/op 0.94
copy serialized Status (84 B) 1.0570 us/op 1.1740 us/op 0.90
transfer serialized SignedVoluntaryExit (112 B) 1.3630 us/op 1.4620 us/op 0.93
copy serialized SignedVoluntaryExit (112 B) 1.0900 us/op 1.2060 us/op 0.90
transfer serialized ProposerSlashing (416 B) 2.5020 us/op 1.5520 us/op 1.61
copy serialized ProposerSlashing (416 B) 1.7280 us/op 1.3760 us/op 1.26
transfer serialized Attestation (485 B) 2.1020 us/op 1.5580 us/op 1.35
copy serialized Attestation (485 B) 1.6730 us/op 1.4470 us/op 1.16
transfer serialized AttesterSlashing (33232 B) 2.3270 us/op 1.7540 us/op 1.33
copy serialized AttesterSlashing (33232 B) 5.0070 us/op 3.7900 us/op 1.32
transfer serialized Small SignedBeaconBlock (128000 B) 2.4680 us/op 2.2270 us/op 1.11
copy serialized Small SignedBeaconBlock (128000 B) 15.149 us/op 9.4900 us/op 1.60
transfer serialized Avg SignedBeaconBlock (200000 B) 2.7110 us/op 2.3660 us/op 1.15
copy serialized Avg SignedBeaconBlock (200000 B) 11.817 us/op 13.623 us/op 0.87
transfer serialized BlobsSidecar (524380 B) 2.5490 us/op 2.9430 us/op 0.87
copy serialized BlobsSidecar (524380 B) 74.706 us/op 75.550 us/op 0.99
transfer serialized Big SignedBeaconBlock (1000000 B) 2.9660 us/op 2.9160 us/op 1.02
copy serialized Big SignedBeaconBlock (1000000 B) 169.68 us/op 154.13 us/op 1.10
pass gossip attestations to forkchoice per slot 2.4109 ms/op 2.7926 ms/op 0.86
forkChoice updateHead vc 100000 bc 64 eq 0 560.79 us/op 426.91 us/op 1.31
forkChoice updateHead vc 600000 bc 64 eq 0 2.5224 ms/op 2.5391 ms/op 0.99
forkChoice updateHead vc 1000000 bc 64 eq 0 4.2144 ms/op 4.3560 ms/op 0.97
forkChoice updateHead vc 600000 bc 320 eq 0 2.5693 ms/op 2.6182 ms/op 0.98
forkChoice updateHead vc 600000 bc 1200 eq 0 2.5255 ms/op 2.7149 ms/op 0.93
forkChoice updateHead vc 600000 bc 7200 eq 0 2.8142 ms/op 3.7385 ms/op 0.75
forkChoice updateHead vc 600000 bc 64 eq 1000 9.5760 ms/op 9.6213 ms/op 1.00
forkChoice updateHead vc 600000 bc 64 eq 10000 9.4343 ms/op 9.4834 ms/op 0.99
forkChoice updateHead vc 600000 bc 64 eq 300000 11.681 ms/op 11.980 ms/op 0.98
computeDeltas 500000 validators 300 proto nodes 2.9194 ms/op 3.0627 ms/op 0.95
computeDeltas 500000 validators 1200 proto nodes 2.9971 ms/op 3.0399 ms/op 0.99
computeDeltas 500000 validators 7200 proto nodes 2.9783 ms/op 2.9911 ms/op 1.00
computeDeltas 750000 validators 300 proto nodes 4.3958 ms/op 4.7289 ms/op 0.93
computeDeltas 750000 validators 1200 proto nodes 4.4441 ms/op 4.6347 ms/op 0.96
computeDeltas 750000 validators 7200 proto nodes 4.4134 ms/op 4.6151 ms/op 0.96
computeDeltas 1400000 validators 300 proto nodes 7.9677 ms/op 8.3119 ms/op 0.96
computeDeltas 1400000 validators 1200 proto nodes 8.0976 ms/op 8.1609 ms/op 0.99
computeDeltas 1400000 validators 7200 proto nodes 7.9213 ms/op 8.2134 ms/op 0.96
computeDeltas 2100000 validators 300 proto nodes 12.364 ms/op 12.282 ms/op 1.01
computeDeltas 2100000 validators 1200 proto nodes 12.146 ms/op 12.577 ms/op 0.97
computeDeltas 2100000 validators 7200 proto nodes 11.985 ms/op 12.910 ms/op 0.93
altair processAttestation - 250000 vs - 7PWei normalcase 1.4360 ms/op 1.5401 ms/op 0.93
altair processAttestation - 250000 vs - 7PWei worstcase 2.2756 ms/op 2.2254 ms/op 1.02
altair processAttestation - setStatus - 1/6 committees join 77.074 us/op 74.810 us/op 1.03
altair processAttestation - setStatus - 1/3 committees join 135.55 us/op 142.85 us/op 0.95
altair processAttestation - setStatus - 1/2 committees join 202.87 us/op 216.25 us/op 0.94
altair processAttestation - setStatus - 2/3 committees join 267.53 us/op 273.63 us/op 0.98
altair processAttestation - setStatus - 4/5 committees join 392.14 us/op 394.40 us/op 0.99
altair processAttestation - setStatus - 100% committees join 475.14 us/op 467.08 us/op 1.02
altair processBlock - 250000 vs - 7PWei normalcase 4.2141 ms/op 3.1173 ms/op 1.35
altair processBlock - 250000 vs - 7PWei normalcase hashState 26.402 ms/op 20.148 ms/op 1.31
altair processBlock - 250000 vs - 7PWei worstcase 38.125 ms/op 35.478 ms/op 1.07
altair processBlock - 250000 vs - 7PWei worstcase hashState 63.249 ms/op 70.610 ms/op 0.90
phase0 processBlock - 250000 vs - 7PWei normalcase 2.1677 ms/op 1.9545 ms/op 1.11
phase0 processBlock - 250000 vs - 7PWei worstcase 23.774 ms/op 25.429 ms/op 0.93
altair processEth1Data - 250000 vs - 7PWei normalcase 252.43 us/op 247.95 us/op 1.02
getExpectedWithdrawals 250000 eb:1,eth1:1,we:0,wn:0,smpl:15 5.8170 us/op 6.0540 us/op 0.96
getExpectedWithdrawals 250000 eb:0.95,eth1:0.1,we:0.05,wn:0,smpl:219 24.330 us/op 16.441 us/op 1.48
getExpectedWithdrawals 250000 eb:0.95,eth1:0.3,we:0.05,wn:0,smpl:42 10.432 us/op 8.2150 us/op 1.27
getExpectedWithdrawals 250000 eb:0.95,eth1:0.7,we:0.05,wn:0,smpl:18 6.4840 us/op 5.7670 us/op 1.12
getExpectedWithdrawals 250000 eb:0.1,eth1:0.1,we:0,wn:0,smpl:1020 81.944 us/op 85.160 us/op 0.96
getExpectedWithdrawals 250000 eb:0.03,eth1:0.03,we:0,wn:0,smpl:11777 732.90 us/op 662.79 us/op 1.11
getExpectedWithdrawals 250000 eb:0.01,eth1:0.01,we:0,wn:0,smpl:16384 746.40 us/op 1.1798 ms/op 0.63
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,smpl:16384 681.87 us/op 652.58 us/op 1.04
getExpectedWithdrawals 250000 eb:0,eth1:0,we:0,wn:0,nocache,smpl:16384 2.2021 ms/op 2.0388 ms/op 1.08
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,smpl:16384 1.1645 ms/op 1.2019 ms/op 0.97
getExpectedWithdrawals 250000 eb:0,eth1:1,we:0,wn:0,nocache,smpl:16384 3.0131 ms/op 3.1490 ms/op 0.96
Tree 40 250000 create 179.28 ms/op 194.30 ms/op 0.92
Tree 40 250000 get(125000) 112.82 ns/op 149.67 ns/op 0.75
Tree 40 250000 set(125000) 540.91 ns/op 634.88 ns/op 0.85
Tree 40 250000 toArray() 9.8806 ms/op 12.248 ms/op 0.81
Tree 40 250000 iterate all - toArray() + loop 10.027 ms/op 11.756 ms/op 0.85
Tree 40 250000 iterate all - get(i) 53.366 ms/op 47.107 ms/op 1.13
MutableVector 250000 create 12.831 ms/op 17.297 ms/op 0.74
MutableVector 250000 get(125000) 6.2440 ns/op 6.3670 ns/op 0.98
MutableVector 250000 set(125000) 191.09 ns/op 368.82 ns/op 0.52
MutableVector 250000 toArray() 2.8685 ms/op 5.3246 ms/op 0.54
MutableVector 250000 iterate all - toArray() + loop 3.0880 ms/op 4.2869 ms/op 0.72
MutableVector 250000 iterate all - get(i) 1.4887 ms/op 1.5370 ms/op 0.97
Array 250000 create 2.5777 ms/op 3.3638 ms/op 0.77
Array 250000 clone - spread 1.4898 ms/op 1.2673 ms/op 1.18
Array 250000 get(125000) 0.60400 ns/op 0.61800 ns/op 0.98
Array 250000 set(125000) 0.62900 ns/op 0.65400 ns/op 0.96
Array 250000 iterate all - loop 79.729 us/op 77.773 us/op 1.03
effectiveBalanceIncrements clone Uint8Array 300000 15.566 us/op 61.961 us/op 0.25
effectiveBalanceIncrements clone MutableVector 300000 319.00 ns/op 334.00 ns/op 0.96
effectiveBalanceIncrements rw all Uint8Array 300000 171.26 us/op 171.20 us/op 1.00
effectiveBalanceIncrements rw all MutableVector 300000 61.089 ms/op 63.577 ms/op 0.96
phase0 afterProcessEpoch - 250000 vs - 7PWei 80.158 ms/op 78.179 ms/op 1.03
Array.fill - length 1000000 2.8032 ms/op 2.7179 ms/op 1.03
Array push - length 1000000 15.018 ms/op 19.537 ms/op 0.77
Array.get 0.25963 ns/op 0.31950 ns/op 0.81
Uint8Array.get 0.34782 ns/op 0.35816 ns/op 0.97
phase0 beforeProcessEpoch - 250000 vs - 7PWei 18.835 ms/op 23.994 ms/op 0.78
altair processEpoch - mainnet_e81889 302.94 ms/op 380.53 ms/op 0.80
mainnet_e81889 - altair beforeProcessEpoch 21.164 ms/op 23.390 ms/op 0.90
mainnet_e81889 - altair processJustificationAndFinalization 12.513 us/op 22.569 us/op 0.55
mainnet_e81889 - altair processInactivityUpdates 5.6938 ms/op 10.437 ms/op 0.55
mainnet_e81889 - altair processRewardsAndPenalties 49.176 ms/op 69.232 ms/op 0.71
mainnet_e81889 - altair processRegistryUpdates 2.0450 us/op 4.7740 us/op 0.43
mainnet_e81889 - altair processSlashings 798.00 ns/op 1.0420 us/op 0.77
mainnet_e81889 - altair processEth1DataReset 718.00 ns/op 995.00 ns/op 0.72
mainnet_e81889 - altair processEffectiveBalanceUpdates 886.07 us/op 2.8388 ms/op 0.31
mainnet_e81889 - altair processSlashingsReset 1.5130 us/op 5.7720 us/op 0.26
mainnet_e81889 - altair processRandaoMixesReset 2.9480 us/op 7.4340 us/op 0.40
mainnet_e81889 - altair processHistoricalRootsUpdate 759.00 ns/op 1.5050 us/op 0.50
mainnet_e81889 - altair processParticipationFlagUpdates 2.5480 us/op 2.0870 us/op 1.22
mainnet_e81889 - altair processSyncCommitteeUpdates 921.00 ns/op 741.00 ns/op 1.24
mainnet_e81889 - altair afterProcessEpoch 84.515 ms/op 75.074 ms/op 1.13
capella processEpoch - mainnet_e217614 1.3585 s/op 1.1964 s/op 1.14
mainnet_e217614 - capella beforeProcessEpoch 71.837 ms/op 73.537 ms/op 0.98
mainnet_e217614 - capella processJustificationAndFinalization 26.634 us/op 13.446 us/op 1.98
mainnet_e217614 - capella processInactivityUpdates 18.491 ms/op 16.759 ms/op 1.10
mainnet_e217614 - capella processRewardsAndPenalties 239.84 ms/op 248.65 ms/op 0.96
mainnet_e217614 - capella processRegistryUpdates 13.615 us/op 11.336 us/op 1.20
mainnet_e217614 - capella processSlashings 912.00 ns/op 866.00 ns/op 1.05
mainnet_e217614 - capella processEth1DataReset 909.00 ns/op 682.00 ns/op 1.33
mainnet_e217614 - capella processEffectiveBalanceUpdates 18.065 ms/op 11.665 ms/op 1.55
mainnet_e217614 - capella processSlashingsReset 4.9380 us/op 2.4620 us/op 2.01
mainnet_e217614 - capella processRandaoMixesReset 5.7270 us/op 3.5970 us/op 1.59
mainnet_e217614 - capella processHistoricalRootsUpdate 1.4680 us/op 704.00 ns/op 2.09
mainnet_e217614 - capella processParticipationFlagUpdates 2.3710 us/op 1.8100 us/op 1.31
mainnet_e217614 - capella afterProcessEpoch 212.69 ms/op 196.48 ms/op 1.08
phase0 processEpoch - mainnet_e58758 448.07 ms/op 345.84 ms/op 1.30
mainnet_e58758 - phase0 beforeProcessEpoch 100.50 ms/op 70.299 ms/op 1.43
mainnet_e58758 - phase0 processJustificationAndFinalization 29.125 us/op 12.206 us/op 2.39
mainnet_e58758 - phase0 processRewardsAndPenalties 36.896 ms/op 33.229 ms/op 1.11
mainnet_e58758 - phase0 processRegistryUpdates 11.065 us/op 7.9050 us/op 1.40
mainnet_e58758 - phase0 processSlashings 738.00 ns/op 429.00 ns/op 1.72
mainnet_e58758 - phase0 processEth1DataReset 826.00 ns/op 436.00 ns/op 1.89
mainnet_e58758 - phase0 processEffectiveBalanceUpdates 893.24 us/op 787.93 us/op 1.13
mainnet_e58758 - phase0 processSlashingsReset 4.1580 us/op 5.7780 us/op 0.72
mainnet_e58758 - phase0 processRandaoMixesReset 8.1010 us/op 3.4520 us/op 2.35
mainnet_e58758 - phase0 processHistoricalRootsUpdate 930.00 ns/op 812.00 ns/op 1.15
mainnet_e58758 - phase0 processParticipationRecordUpdates 4.8280 us/op 3.4280 us/op 1.41
mainnet_e58758 - phase0 afterProcessEpoch 72.413 ms/op 61.985 ms/op 1.17
phase0 processEffectiveBalanceUpdates - 250000 normalcase 921.51 us/op 835.28 us/op 1.10
phase0 processEffectiveBalanceUpdates - 250000 worstcase 0.5 1.7999 ms/op 1.7232 ms/op 1.04
altair processInactivityUpdates - 250000 normalcase 15.761 ms/op 16.160 ms/op 0.98
altair processInactivityUpdates - 250000 worstcase 17.213 ms/op 17.038 ms/op 1.01
phase0 processRegistryUpdates - 250000 normalcase 8.2190 us/op 6.2790 us/op 1.31
phase0 processRegistryUpdates - 250000 badcase_full_deposits 313.15 us/op 307.56 us/op 1.02
phase0 processRegistryUpdates - 250000 worstcase 0.5 116.99 ms/op 110.64 ms/op 1.06
altair processRewardsAndPenalties - 250000 normalcase 50.168 ms/op 40.407 ms/op 1.24
altair processRewardsAndPenalties - 250000 worstcase 34.772 ms/op 45.614 ms/op 0.76
phase0 getAttestationDeltas - 250000 normalcase 6.3505 ms/op 9.7247 ms/op 0.65
phase0 getAttestationDeltas - 250000 worstcase 6.4312 ms/op 7.3208 ms/op 0.88
phase0 processSlashings - 250000 worstcase 92.269 us/op 91.465 us/op 1.01
altair processSyncCommitteeUpdates - 250000 96.670 ms/op 93.373 ms/op 1.04
BeaconState.hashTreeRoot - No change 484.00 ns/op 483.00 ns/op 1.00
BeaconState.hashTreeRoot - 1 full validator 81.979 us/op 81.728 us/op 1.00
BeaconState.hashTreeRoot - 32 full validator 1.2743 ms/op 1.1766 ms/op 1.08
BeaconState.hashTreeRoot - 512 full validator 9.4449 ms/op 13.484 ms/op 0.70
BeaconState.hashTreeRoot - 1 validator.effectiveBalance 157.20 us/op 130.36 us/op 1.21
BeaconState.hashTreeRoot - 32 validator.effectiveBalance 1.7630 ms/op 2.2585 ms/op 0.78
BeaconState.hashTreeRoot - 512 validator.effectiveBalance 29.872 ms/op 23.216 ms/op 1.29
BeaconState.hashTreeRoot - 1 balances 96.418 us/op 105.60 us/op 0.91
BeaconState.hashTreeRoot - 32 balances 1.1116 ms/op 1.0965 ms/op 1.01
BeaconState.hashTreeRoot - 512 balances 9.9807 ms/op 6.0743 ms/op 1.64
BeaconState.hashTreeRoot - 250000 balances 133.23 ms/op 143.85 ms/op 0.93
aggregationBits - 2048 els - zipIndexesInBitList 19.143 us/op 21.135 us/op 0.91
byteArrayEquals 32 50.820 ns/op 49.621 ns/op 1.02
Buffer.compare 32 16.464 ns/op 16.255 ns/op 1.01
byteArrayEquals 1024 1.2720 us/op 1.3090 us/op 0.97
Buffer.compare 1024 23.762 ns/op 24.463 ns/op 0.97
byteArrayEquals 16384 20.117 us/op 20.403 us/op 0.99
Buffer.compare 16384 202.18 ns/op 208.14 ns/op 0.97
byteArrayEquals 123687377 150.51 ms/op 148.76 ms/op 1.01
Buffer.compare 123687377 4.5696 ms/op 4.9662 ms/op 0.92
byteArrayEquals 32 - diff last byte 47.077 ns/op 48.030 ns/op 0.98
Buffer.compare 32 - diff last byte 15.894 ns/op 18.063 ns/op 0.88
byteArrayEquals 1024 - diff last byte 1.2776 us/op 1.2652 us/op 1.01
Buffer.compare 1024 - diff last byte 23.793 ns/op 23.671 ns/op 1.01
byteArrayEquals 16384 - diff last byte 20.049 us/op 20.175 us/op 0.99
Buffer.compare 16384 - diff last byte 181.76 ns/op 209.97 ns/op 0.87
byteArrayEquals 123687377 - diff last byte 150.66 ms/op 151.42 ms/op 0.99
Buffer.compare 123687377 - diff last byte 5.4096 ms/op 4.1535 ms/op 1.30
byteArrayEquals 32 - random bytes 4.6740 ns/op 4.9080 ns/op 0.95
Buffer.compare 32 - random bytes 14.910 ns/op 16.164 ns/op 0.92
byteArrayEquals 1024 - random bytes 4.8510 ns/op 4.9000 ns/op 0.99
Buffer.compare 1024 - random bytes 14.862 ns/op 16.341 ns/op 0.91
byteArrayEquals 16384 - random bytes 4.7640 ns/op 4.9340 ns/op 0.97
Buffer.compare 16384 - random bytes 14.913 ns/op 15.898 ns/op 0.94
byteArrayEquals 123687377 - random bytes 7.4900 ns/op 7.9300 ns/op 0.94
Buffer.compare 123687377 - random bytes 17.660 ns/op 19.980 ns/op 0.88
regular array get 100000 times 29.696 us/op 30.721 us/op 0.97
wrappedArray get 100000 times 29.520 us/op 30.744 us/op 0.96
arrayWithProxy get 100000 times 9.3676 ms/op 10.097 ms/op 0.93
ssz.Root.equals 42.552 ns/op 42.737 ns/op 1.00
byteArrayEquals 41.168 ns/op 41.315 ns/op 1.00
Buffer.compare 8.6040 ns/op 8.5290 ns/op 1.01
shuffle list - 16384 els 5.4972 ms/op 5.3619 ms/op 1.03
shuffle list - 250000 els 80.564 ms/op 78.890 ms/op 1.02
processSlot - 1 slots 9.3590 us/op 13.035 us/op 0.72
processSlot - 32 slots 2.3672 ms/op 2.7752 ms/op 0.85
getEffectiveBalanceIncrementsZeroInactive - 250000 vs - 7PWei 37.541 ms/op 41.244 ms/op 0.91
getCommitteeAssignments - req 1 vs - 250000 vc 1.7965 ms/op 1.8990 ms/op 0.95
getCommitteeAssignments - req 100 vs - 250000 vc 3.5165 ms/op 3.5554 ms/op 0.99
getCommitteeAssignments - req 1000 vs - 250000 vc 3.7557 ms/op 3.8388 ms/op 0.98
findModifiedValidators - 10000 modified validators 242.63 ms/op 242.77 ms/op 1.00
findModifiedValidators - 1000 modified validators 154.51 ms/op 139.23 ms/op 1.11
findModifiedValidators - 100 modified validators 131.64 ms/op 134.75 ms/op 0.98
findModifiedValidators - 10 modified validators 138.10 ms/op 130.98 ms/op 1.05
findModifiedValidators - 1 modified validators 117.94 ms/op 149.37 ms/op 0.79
findModifiedValidators - no difference 129.03 ms/op 160.25 ms/op 0.81
compare ViewDUs 2.8961 s/op 3.0351 s/op 0.95
compare each validator Uint8Array 1.4013 s/op 1.5140 s/op 0.93
compare ViewDU to Uint8Array 626.58 ms/op 651.28 ms/op 0.96
migrate state 1000000 validators, 24 modified, 0 new 518.03 ms/op 524.51 ms/op 0.99
migrate state 1000000 validators, 1700 modified, 1000 new 822.27 ms/op 727.18 ms/op 1.13
migrate state 1000000 validators, 3400 modified, 2000 new 995.18 ms/op 906.29 ms/op 1.10
migrate state 1500000 validators, 24 modified, 0 new 600.53 ms/op 485.80 ms/op 1.24
migrate state 1500000 validators, 1700 modified, 1000 new 860.61 ms/op 816.74 ms/op 1.05
migrate state 1500000 validators, 3400 modified, 2000 new 1.1711 s/op 1.0334 s/op 1.13
RootCache.getBlockRootAtSlot - 250000 vs - 7PWei 6.4600 ns/op 6.0800 ns/op 1.06
state getBlockRootAtSlot - 250000 vs - 7PWei 521.64 ns/op 652.34 ns/op 0.80
computeProposers - vc 250000 6.2124 ms/op 6.1335 ms/op 1.01
computeEpochShuffling - vc 250000 83.580 ms/op 76.014 ms/op 1.10
getNextSyncCommittee - vc 250000 105.11 ms/op 104.99 ms/op 1.00
computeSigningRoot for AttestationData 27.483 us/op 20.805 us/op 1.32
hash AttestationData serialized data then Buffer.toString(base64) 1.3035 us/op 1.1798 us/op 1.10
toHexString serialized data 959.01 ns/op 792.81 ns/op 1.21
Buffer.toString(base64) 169.32 ns/op 132.86 ns/op 1.27
block root to RootHex using toHex 127.71 ns/op
block root to RootHex using toRootHex 82.095 ns/op

by benchmarkbot/action

Copy link

codecov bot commented Aug 13, 2024

Codecov Report

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

Project coverage is 49.24%. Comparing base (a0f16eb) to head (fa25623).
Report is 5 commits behind head on unstable.

Additional details and impacted files
@@             Coverage Diff              @@
##           unstable    #7016      +/-   ##
============================================
+ Coverage     49.23%   49.24%   +0.01%     
============================================
  Files           578      578              
  Lines         37426    37438      +12     
  Branches       2165     2172       +7     
============================================
+ Hits          18426    18437      +11     
- Misses        18960    18961       +1     
  Partials         40       40              

@twoeths
Copy link
Contributor Author

twoeths commented Aug 13, 2024

this is on the test mainnet node, Scavenge is ~2.2x% after 4h of running (~2.91% on unstable and ~2.73% on stable)

Screenshot 2024-08-13 at 14 22 10

forkchoice updateHead() is ~5ms faster
Screenshot 2024-08-13 at 14 23 08

@@ -27,7 +27,7 @@
"build:watch": "yarn run build --watch",
"build:release": "yarn clean && yarn build",
"check-build": "node -e \"(async function() { await import('./lib/index.js') })()\"",
"check-types": "tsc && vitest --run --typecheck --dir test/types/",
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 somehow this vitest command scans through the new test/perf folder and it caused error, even after I added --exclude option. Note that the benchmarks go with mocha

I guess it's still ok to drop this check because we also scan through unit test

Copy link
Member

Choose a reason for hiding this comment

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

We need to run type checks separately because of --typecheck flag and those are not checked as part of unit tests. This seems to be an issue on vitest side, it shouldn't even scan files in this folder, I tried all possible options from here but none worked other than setting ignoreSourceErrors=true which I think is ok here and only affect typecheck tests.

@twoeths twoeths marked this pull request as ready for review August 13, 2024 07:27
@twoeths twoeths requested a review from a team as a code owner August 13, 2024 07:27
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.

There are few more places we could use toRootHex should those be updated as well?

Eg.

const blockRoot = toHex(chain.config.getForkTypes(slot).BeaconBlock.hashTreeRoot(signedBlock.message));
// bodyRoot should be the same to produced block
const bodyRoot = toHex(chain.config.getForkTypes(slot).BeaconBlockBody.hashTreeRoot(signedBlock.message.body));

// Shared buffer to convert root to hex
const rootBuf = Buffer.alloc(32);

export function toRootHex(root: Uint8Array): string {
Copy link
Member

Choose a reason for hiding this comment

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

what happens if you pass in a root > 32 bytes? I would assume it just cuts of the end but we could consider throwing a more explicit error if this function is misused

@wemeetagain wemeetagain enabled auto-merge (squash) August 13, 2024 20:24
@wemeetagain wemeetagain merged commit 44b2156 into unstable Aug 13, 2024
20 checks passed
@wemeetagain wemeetagain deleted the te/improve_msgIdToStrFn branch August 13, 2024 20:39
@twoeths
Copy link
Contributor Author

twoeths commented Aug 14, 2024

it was confirmed in docker deployment (unstable mainnet node)

Screenshot 2024-08-14 at 09 27 16

updateHead() time somehow increased in this node
Screenshot 2024-08-14 at 09 25 41

for feat4 mainnet node and all other nodes like in unstable-64 updateHead() is better

Screenshot 2024-08-14 at 09 26 47

updateHead() is not modified in this PR anyway..

@twoeths
Copy link
Contributor Author

twoeths commented Aug 15, 2024

the unstable mainnet node updateHead() got back to expected value after the latest #7021 was merged

Screenshot 2024-08-15 at 10 42 58

also it works well with beta mainnet node and other nodes
Screenshot 2024-08-15 at 10 43 35

philknows pushed a commit that referenced this pull request Sep 3, 2024
* fix: improve message id to string conversion

* fix: use shared Buffers for sszBytes util

* feat: implement toRootHex()

* fix: lint and check-types

* Fix type checks

* Add comment to vitest config

* Update packages/utils/src/bytes.ts

---------

Co-authored-by: Nico Flaig <nflaig@protonmail.com>
Co-authored-by: Cayman <caymannava@gmail.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