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 HashComputationLevel using LinkedList #389

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Jul 23, 2024

Motivation

Description

  • Move HashComputation type and its utils to a separate class
  • Implement HashComputationLevel to be a linked-list like to save memory allocation:
    • when push() may reuse the existing item of LinkedList instead of allocate one
    • when it grows it only need to add one more list items, instead of allocating a whole new array to reuse and save memory
    • loop speed is same to a regular array
    • we don't need random access
  • others:
    • hashtree: allocate destNodes variable once, set it as default
    • subtreeFillToContents + setNodesAtDepth: destructure params in order not to allocate temporary objects at the consumer side

test result was persisted here

part of #378

cc @wemeetagain @g11tech

Copy link

github-actions bot commented Jul 23, 2024

Performance Report

✔️ no performance regression detected

🚀🚀 Significant benchmark improvement detected

Benchmark suite Current: 85fae47 Previous: 1578883 Ratio
hashTreeRoot Attestation - struct 15.164 us/op 62.645 us/op 0.24
hashTreeRoot SignedAggregateAndProof - struct 23.232 us/op 70.788 us/op 0.33
hashTreeRoot SyncCommitteeMessage - struct 5.7690 us/op 18.128 us/op 0.32
Full benchmark results
Benchmark suite Current: 85fae47 Previous: 1578883 Ratio
digestTwoHashObjects 50023 times 47.789 ms/op 48.098 ms/op 0.99
digest64 50023 times 50.418 ms/op 51.043 ms/op 0.99
digest 50023 times 51.651 ms/op 58.931 ms/op 0.88
input length 32 1.1580 us/op 1.4760 us/op 0.78
input length 64 1.3310 us/op 1.6290 us/op 0.82
input length 128 2.2610 us/op 2.6700 us/op 0.85
input length 256 3.3730 us/op 3.8610 us/op 0.87
input length 512 5.5750 us/op 6.2890 us/op 0.89
input length 1024 10.946 us/op 11.592 us/op 0.94
digest 1000000 times 842.72 ms/op 894.07 ms/op 0.94
hashObjectToByteArray 50023 times 1.4452 ms/op 1.4538 ms/op 0.99
byteArrayToHashObject 50023 times 2.4814 ms/op 2.8036 ms/op 0.89
digest64 200092 times 209.26 ms/op 237.79 ms/op 0.88
hash 200092 times using batchHash4UintArray64s 218.08 ms/op 242.40 ms/op 0.90
digest64HashObjects 200092 times 195.84 ms/op 208.10 ms/op 0.94
hash 200092 times using batchHash4HashObjectInputs 205.42 ms/op 223.96 ms/op 0.92
getGindicesAtDepth 4.1910 us/op 4.6070 us/op 0.91
iterateAtDepth 7.7000 us/op 8.5470 us/op 0.90
getGindexBits 461.00 ns/op 543.00 ns/op 0.85
gindexIterator 1.0530 us/op 1.1530 us/op 0.91
HashComputationLevel.push then loop 13.409 ms/op
HashComputation[] push then loop 19.239 ms/op
hash 2 Uint8Array 500000 times - as-sha256 508.08 ms/op 589.77 ms/op 0.86
hashTwoObjects 500000 times - as-sha256 499.58 ms/op 502.44 ms/op 0.99
executeHashComputations - as-sha256 46.835 ms/op 46.575 ms/op 1.01
hash 2 Uint8Array 500000 times - noble 1.1085 s/op 1.1988 s/op 0.92
hashTwoObjects 500000 times - noble 1.5583 s/op 1.7515 s/op 0.89
executeHashComputations - noble 41.811 ms/op 38.344 ms/op 1.09
hash 2 Uint8Array 500000 times - hashtree 224.88 ms/op 234.30 ms/op 0.96
hashTwoObjects 500000 times - hashtree 215.44 ms/op 219.16 ms/op 0.98
executeHashComputations - hashtree 10.659 ms/op 16.988 ms/op 0.63
getNodeH() x7812.5 avg hindex 12.170 us/op 13.049 us/op 0.93
getNodeH() x7812.5 index 0 6.2300 us/op 6.2460 us/op 1.00
getNodeH() x7812.5 index 7 6.2600 us/op 6.2530 us/op 1.00
getNodeH() x7812.5 index 7 with key array 6.2690 us/op 6.2390 us/op 1.00
new LeafNode() x7812.5 14.679 us/op 14.671 us/op 1.00
getHashComputations 250000 nodes 19.536 ms/op 18.731 ms/op 1.04
batchHash 250000 nodes 330.55 ms/op 351.19 ms/op 0.94
get root 250000 nodes 852.63 ms/op 969.79 ms/op 0.88
getHashComputations 500000 nodes 32.452 ms/op 36.103 ms/op 0.90
batchHash 500000 nodes 590.04 ms/op 621.06 ms/op 0.95
get root 500000 nodes 1.6995 s/op 1.9052 s/op 0.89
getHashComputations 1000000 nodes 65.007 ms/op 85.949 ms/op 0.76
batchHash 1000000 nodes 1.1991 s/op 1.2345 s/op 0.97
get root 1000000 nodes 3.3642 s/op 3.8316 s/op 0.88
multiproof - depth 15, 1 requested leaves 8.0930 us/op 9.6840 us/op 0.84
tree offset multiproof - depth 15, 1 requested leaves 19.239 us/op 20.935 us/op 0.92
compact multiproof - depth 15, 1 requested leaves 3.4620 us/op 4.4030 us/op 0.79
multiproof - depth 15, 2 requested leaves 12.461 us/op 14.202 us/op 0.88
tree offset multiproof - depth 15, 2 requested leaves 22.574 us/op 24.979 us/op 0.90
compact multiproof - depth 15, 2 requested leaves 3.4230 us/op 4.4450 us/op 0.77
multiproof - depth 15, 3 requested leaves 16.179 us/op 19.463 us/op 0.83
tree offset multiproof - depth 15, 3 requested leaves 28.255 us/op 32.084 us/op 0.88
compact multiproof - depth 15, 3 requested leaves 5.1350 us/op 5.9560 us/op 0.86
multiproof - depth 15, 4 requested leaves 23.201 us/op 25.203 us/op 0.92
tree offset multiproof - depth 15, 4 requested leaves 38.235 us/op 39.971 us/op 0.96
compact multiproof - depth 15, 4 requested leaves 5.0130 us/op 7.0430 us/op 0.71
packedRootsBytesToLeafNodes bytes 4000 offset 0 1.8340 us/op 3.4100 us/op 0.54
packedRootsBytesToLeafNodes bytes 4000 offset 1 1.8290 us/op 2.8950 us/op 0.63
packedRootsBytesToLeafNodes bytes 4000 offset 2 1.8230 us/op 2.6660 us/op 0.68
packedRootsBytesToLeafNodes bytes 4000 offset 3 1.8320 us/op 2.4340 us/op 0.75
subtreeFillToContents depth 40 count 250000 41.935 ms/op 45.302 ms/op 0.93
setRoot - gindexBitstring 9.5834 ms/op 11.446 ms/op 0.84
setRoot - gindex 10.408 ms/op 12.246 ms/op 0.85
getRoot - gindexBitstring 2.6006 ms/op 2.7112 ms/op 0.96
getRoot - gindex 3.2579 ms/op 3.6256 ms/op 0.90
getHashObject then setHashObject 11.050 ms/op 12.206 ms/op 0.91
setNodeWithFn 8.8988 ms/op 9.6518 ms/op 0.92
getNodeAtDepth depth 0 x100000 1.1192 ms/op 1.1147 ms/op 1.00
setNodeAtDepth depth 0 x100000 2.6708 ms/op 2.9412 ms/op 0.91
getNodesAtDepth depth 0 x100000 1.0539 ms/op 1.0527 ms/op 1.00
setNodesAtDepth depth 0 x100000 1.5164 ms/op 1.4598 ms/op 1.04
getNodeAtDepth depth 1 x100000 1.1893 ms/op 1.1820 ms/op 1.01
setNodeAtDepth depth 1 x100000 5.7572 ms/op 6.3041 ms/op 0.91
getNodesAtDepth depth 1 x100000 1.2082 ms/op 1.1771 ms/op 1.03
setNodesAtDepth depth 1 x100000 4.7649 ms/op 5.2765 ms/op 0.90
getNodeAtDepth depth 2 x100000 1.4556 ms/op 1.4545 ms/op 1.00
setNodeAtDepth depth 2 x100000 9.8727 ms/op 11.988 ms/op 0.82
getNodesAtDepth depth 2 x100000 19.667 ms/op 20.101 ms/op 0.98
setNodesAtDepth depth 2 x100000 14.268 ms/op 14.807 ms/op 0.96
tree.getNodesAtDepth - gindexes 9.3934 ms/op 9.9621 ms/op 0.94
tree.getNodesAtDepth - push all nodes 2.2169 ms/op 2.1940 ms/op 1.01
tree.getNodesAtDepth - navigation 234.88 us/op 232.52 us/op 1.01
tree.setNodesAtDepth - indexes 428.68 us/op 487.95 us/op 0.88
set at depth 8 536.00 ns/op 588.00 ns/op 0.91
set at depth 16 667.00 ns/op 807.00 ns/op 0.83
set at depth 32 1.0460 us/op 1.2130 us/op 0.86
iterateNodesAtDepth 8 256 14.055 us/op 14.946 us/op 0.94
getNodesAtDepth 8 256 3.5350 us/op 3.7070 us/op 0.95
iterateNodesAtDepth 16 65536 4.6568 ms/op 4.5803 ms/op 1.02
getNodesAtDepth 16 65536 1.8261 ms/op 1.7377 ms/op 1.05
iterateNodesAtDepth 32 250000 16.876 ms/op 16.474 ms/op 1.02
getNodesAtDepth 32 250000 4.6530 ms/op 5.0082 ms/op 0.93
iterateNodesAtDepth 40 250000 16.543 ms/op 16.404 ms/op 1.01
getNodesAtDepth 40 250000 4.6580 ms/op 5.1320 ms/op 0.91
250000 validators root getter 954.62 ms/op
250000 validators batchHash() 308.73 ms/op
250000 validators hashComputations 16.898 ms/op
bitlist bytes to struct (120,90) 587.00 ns/op 586.00 ns/op 1.00
bitlist bytes to tree (120,90) 2.4360 us/op 2.7340 us/op 0.89
bitlist bytes to struct (2048,2048) 967.00 ns/op 1.2650 us/op 0.76
bitlist bytes to tree (2048,2048) 3.6650 us/op 4.3770 us/op 0.84
ByteListType - deserialize 7.5472 ms/op 10.544 ms/op 0.72
BasicListType - deserialize 14.420 ms/op 14.148 ms/op 1.02
ByteListType - serialize 7.5398 ms/op 10.549 ms/op 0.71
BasicListType - serialize 10.303 ms/op 14.591 ms/op 0.71
BasicListType - tree_convertToStruct 26.014 ms/op 27.925 ms/op 0.93
List[uint8, 68719476736] len 300000 ViewDU.getAll() + iterate 4.3955 ms/op 6.6210 ms/op 0.66
List[uint8, 68719476736] len 300000 ViewDU.get(i) 3.9849 ms/op 3.9754 ms/op 1.00
Array.push len 300000 empty Array - number 6.7311 ms/op 7.9548 ms/op 0.85
Array.set len 300000 from new Array - number 1.9128 ms/op 2.8766 ms/op 0.66
Array.set len 300000 - number 5.9899 ms/op 7.3264 ms/op 0.82
Uint8Array.set len 300000 379.74 us/op 393.20 us/op 0.97
Uint32Array.set len 300000 457.99 us/op 479.10 us/op 0.96
Container({a: uint8, b: uint8}) getViewDU x300000 53.914 ms/op 57.757 ms/op 0.93
ContainerNodeStruct({a: uint8, b: uint8}) getViewDU x300000 10.851 ms/op 11.975 ms/op 0.91
List(Container) len 300000 ViewDU.getAllReadonly() + iterate 211.41 ms/op 222.54 ms/op 0.95
List(Container) len 300000 ViewDU.getAllReadonlyValues() + iterate 260.20 ms/op 281.44 ms/op 0.92
List(Container) len 300000 ViewDU.get(i) 6.7027 ms/op 10.823 ms/op 0.62
List(Container) len 300000 ViewDU.getReadonly(i) 7.0261 ms/op 9.5995 ms/op 0.73
List(ContainerNodeStruct) len 300000 ViewDU.getAllReadonly() + iterate 39.149 ms/op 40.461 ms/op 0.97
List(ContainerNodeStruct) len 300000 ViewDU.getAllReadonlyValues() + iterate 4.7394 ms/op 6.7733 ms/op 0.70
List(ContainerNodeStruct) len 300000 ViewDU.get(i) 6.4215 ms/op 10.390 ms/op 0.62
List(ContainerNodeStruct) len 300000 ViewDU.getReadonly(i) 6.1738 ms/op 9.7459 ms/op 0.63
Array.push len 300000 empty Array - object 6.4417 ms/op 7.2653 ms/op 0.89
Array.set len 300000 from new Array - object 2.0553 ms/op 3.4506 ms/op 0.60
Array.set len 300000 - object 6.0640 ms/op 7.1740 ms/op 0.85
cachePermanentRootStruct no cache 5.7600 us/op 9.9890 us/op 0.58
cachePermanentRootStruct with cache 227.00 ns/op 283.00 ns/op 0.80
epochParticipation len 250000 rws 7813 2.2826 ms/op 2.4283 ms/op 0.94
deserialize Attestation - tree 4.2570 us/op 4.7050 us/op 0.90
deserialize Attestation - struct 1.8630 us/op 2.2840 us/op 0.82
deserialize SignedAggregateAndProof - tree 3.7940 us/op 4.8490 us/op 0.78
deserialize SignedAggregateAndProof - struct 3.3690 us/op 4.0770 us/op 0.83
deserialize SyncCommitteeMessage - tree 1.2070 us/op 1.2650 us/op 0.95
deserialize SyncCommitteeMessage - struct 1.0260 us/op 1.1920 us/op 0.86
deserialize SignedContributionAndProof - tree 2.1040 us/op 2.4780 us/op 0.85
deserialize SignedContributionAndProof - struct 2.3150 us/op 2.5910 us/op 0.89
deserialize SignedBeaconBlock - tree 212.92 us/op 245.64 us/op 0.87
deserialize SignedBeaconBlock - struct 121.56 us/op 130.47 us/op 0.93
BeaconState vc 300000 - deserialize tree 574.94 ms/op 606.77 ms/op 0.95
BeaconState vc 300000 - serialize tree 132.94 ms/op 140.97 ms/op 0.94
BeaconState.historicalRoots vc 300000 - deserialize tree 747.00 ns/op 870.00 ns/op 0.86
BeaconState.historicalRoots vc 300000 - serialize tree 620.00 ns/op 744.00 ns/op 0.83
BeaconState.validators vc 300000 - deserialize tree 522.07 ms/op 561.01 ms/op 0.93
BeaconState.validators vc 300000 - serialize tree 100.01 ms/op 99.779 ms/op 1.00
BeaconState.balances vc 300000 - deserialize tree 20.355 ms/op 21.893 ms/op 0.93
BeaconState.balances vc 300000 - serialize tree 4.3312 ms/op 7.1918 ms/op 0.60
BeaconState.previousEpochParticipation vc 300000 - deserialize tree 562.87 us/op 792.47 us/op 0.71
BeaconState.previousEpochParticipation vc 300000 - serialize tree 282.57 us/op 300.54 us/op 0.94
BeaconState.currentEpochParticipation vc 300000 - deserialize tree 548.01 us/op 827.63 us/op 0.66
BeaconState.currentEpochParticipation vc 300000 - serialize tree 285.06 us/op 304.86 us/op 0.94
BeaconState.inactivityScores vc 300000 - deserialize tree 21.086 ms/op 22.522 ms/op 0.94
BeaconState.inactivityScores vc 300000 - serialize tree 3.0250 ms/op 7.3602 ms/op 0.41
hashTreeRoot Attestation - struct 15.164 us/op 62.645 us/op 0.24
hashTreeRoot Attestation - tree 8.9850 us/op 23.452 us/op 0.38
hashTreeRoot SignedAggregateAndProof - struct 23.232 us/op 70.788 us/op 0.33
hashTreeRoot SignedAggregateAndProof - tree 12.623 us/op 30.654 us/op 0.41
hashTreeRoot SyncCommitteeMessage - struct 5.7690 us/op 18.128 us/op 0.32
hashTreeRoot SyncCommitteeMessage - tree 3.1070 us/op 7.2220 us/op 0.43
hashTreeRoot SignedContributionAndProof - struct 15.521 us/op 38.246 us/op 0.41
hashTreeRoot SignedContributionAndProof - tree 9.7640 us/op 20.813 us/op 0.47
hashTreeRoot SignedBeaconBlock - struct 1.2937 ms/op 2.9015 ms/op 0.45
hashTreeRoot SignedBeaconBlock - tree 752.79 us/op 1.8997 ms/op 0.40
hashTreeRoot Validator - struct 7.7070 us/op 15.298 us/op 0.50
hashTreeRoot Validator - tree 6.6040 us/op 13.129 us/op 0.50
BeaconState vc 300000 - hashTreeRoot tree 2.1274 s/op 4.0034 s/op 0.53
BeaconState.historicalRoots vc 300000 - hashTreeRoot tree 1.0390 us/op 1.6540 us/op 0.63
BeaconState.validators vc 300000 - hashTreeRoot tree 2.0373 s/op 3.8062 s/op 0.54
BeaconState.balances vc 300000 - hashTreeRoot tree 37.097 ms/op 83.211 ms/op 0.45
BeaconState.previousEpochParticipation vc 300000 - hashTreeRoot tree 4.2730 ms/op 10.045 ms/op 0.43
BeaconState.currentEpochParticipation vc 300000 - hashTreeRoot tree 4.2721 ms/op 10.030 ms/op 0.43
BeaconState.inactivityScores vc 300000 - hashTreeRoot tree 34.152 ms/op 81.030 ms/op 0.42
hash64 x18 9.4050 us/op 19.871 us/op 0.47
hashTwoObjects x18 8.8920 us/op 20.332 us/op 0.44
hash64 x1740 898.57 us/op 1.8450 ms/op 0.49
hashTwoObjects x1740 818.59 us/op 1.8995 ms/op 0.43
hash64 x2700000 1.3810 s/op 2.8693 s/op 0.48
hashTwoObjects x2700000 1.2718 s/op 2.9436 s/op 0.43
get_exitEpoch - ContainerType 339.00 ns/op 459.00 ns/op 0.74
get_exitEpoch - ContainerNodeStructType 328.00 ns/op 425.00 ns/op 0.77
set_exitEpoch - ContainerType 359.00 ns/op 461.00 ns/op 0.78
set_exitEpoch - ContainerNodeStructType 329.00 ns/op 446.00 ns/op 0.74
get_pubkey - ContainerType 859.00 ns/op 884.00 ns/op 0.97
get_pubkey - ContainerNodeStructType 337.00 ns/op 439.00 ns/op 0.77
hashTreeRoot - ContainerType 561.00 ns/op 720.00 ns/op 0.78
hashTreeRoot - ContainerNodeStructType 608.00 ns/op 759.00 ns/op 0.80
createProof - ContainerType 5.9570 us/op 5.6070 us/op 1.06
createProof - ContainerNodeStructType 24.348 us/op 27.166 us/op 0.90
serialize - ContainerType 1.8380 us/op 2.1220 us/op 0.87
serialize - ContainerNodeStructType 1.3880 us/op 1.7310 us/op 0.80
set_exitEpoch_and_hashTreeRoot - ContainerType 2.7360 us/op 5.5210 us/op 0.50
set_exitEpoch_and_hashTreeRoot - ContainerNodeStructType 7.3770 us/op 13.800 us/op 0.53
Array - for of 11.725 us/op 5.8690 us/op 2.00
Array - for(;;) 12.215 us/op 5.8750 us/op 2.08
basicListValue.readonlyValuesArray() 4.1652 ms/op 4.9419 ms/op 0.84
basicListValue.readonlyValuesArray() + loop all 4.3989 ms/op 5.1149 ms/op 0.86
compositeListValue.readonlyValuesArray() 29.785 ms/op 29.257 ms/op 1.02
compositeListValue.readonlyValuesArray() + loop all 27.528 ms/op 28.781 ms/op 0.96
Number64UintType - get balances list 4.3151 ms/op 4.6154 ms/op 0.93
Number64UintType - set balances list 9.6031 ms/op 9.7880 ms/op 0.98
Number64UintType - get and increase 10 then set 35.652 ms/op 38.538 ms/op 0.93
Number64UintType - increase 10 using applyDelta 14.969 ms/op 16.731 ms/op 0.89
Number64UintType - increase 10 using applyDeltaInBatch 14.847 ms/op 16.269 ms/op 0.91
tree_newTreeFromUint64Deltas 14.930 ms/op 17.213 ms/op 0.87
unsafeUint8ArrayToTree 32.959 ms/op 31.231 ms/op 1.06
bitLength(50) 235.00 ns/op 233.00 ns/op 1.01
bitLengthStr(50) 227.00 ns/op 217.00 ns/op 1.05
bitLength(8000) 220.00 ns/op 227.00 ns/op 0.97
bitLengthStr(8000) 257.00 ns/op 267.00 ns/op 0.96
bitLength(250000) 223.00 ns/op 228.00 ns/op 0.98
bitLengthStr(250000) 299.00 ns/op 301.00 ns/op 0.99
floor - Math.floor (53) 1.2379 ns/op 1.2385 ns/op 1.00
floor - << 0 (53) 1.2405 ns/op 1.2380 ns/op 1.00
floor - Math.floor (512) 1.2377 ns/op 1.2478 ns/op 0.99
floor - << 0 (512) 1.2372 ns/op 1.2374 ns/op 1.00
fnIf(0) 1.5504 ns/op 1.5457 ns/op 1.00
fnSwitch(0) 2.1642 ns/op 2.1699 ns/op 1.00
fnObj(0) 1.5490 ns/op 1.5492 ns/op 1.00
fnArr(0) 1.5490 ns/op 1.5463 ns/op 1.00
fnIf(4) 2.1719 ns/op 2.1650 ns/op 1.00
fnSwitch(4) 2.1644 ns/op 2.1637 ns/op 1.00
fnObj(4) 1.5474 ns/op 1.5530 ns/op 1.00
fnArr(4) 1.5461 ns/op 1.5476 ns/op 1.00
fnIf(9) 3.1283 ns/op 3.0923 ns/op 1.01
fnSwitch(9) 2.1650 ns/op 2.1645 ns/op 1.00
fnObj(9) 1.5534 ns/op 1.5496 ns/op 1.00
fnArr(9) 1.5463 ns/op 1.5521 ns/op 1.00
Container {a,b,vec} - as struct x100000 124.13 us/op 124.01 us/op 1.00
Container {a,b,vec} - as tree x100000 340.61 us/op 340.82 us/op 1.00
Container {a,vec,b} - as struct x100000 155.17 us/op 155.04 us/op 1.00
Container {a,vec,b} - as tree x100000 371.24 us/op 371.57 us/op 1.00
get 2 props x1000000 - rawObject 309.82 us/op 310.24 us/op 1.00
get 2 props x1000000 - proxy 73.303 ms/op 72.781 ms/op 1.01
get 2 props x1000000 - customObj 310.17 us/op 309.17 us/op 1.00
Simple object binary -> struct 835.00 ns/op 565.00 ns/op 1.48
Simple object binary -> tree_backed 1.7070 us/op 1.0470 us/op 1.63
Simple object struct -> tree_backed 2.3540 us/op 1.6310 us/op 1.44
Simple object tree_backed -> struct 2.3190 us/op 1.5940 us/op 1.45
Simple object struct -> binary 954.00 ns/op 850.00 ns/op 1.12
Simple object tree_backed -> binary 1.6100 us/op 1.3320 us/op 1.21
aggregationBits binary -> struct 613.00 ns/op 470.00 ns/op 1.30
aggregationBits binary -> tree_backed 2.3880 us/op 2.0660 us/op 1.16
aggregationBits struct -> tree_backed 2.8180 us/op 2.4270 us/op 1.16
aggregationBits tree_backed -> struct 1.2180 us/op 1.0350 us/op 1.18
aggregationBits struct -> binary 787.00 ns/op 747.00 ns/op 1.05
aggregationBits tree_backed -> binary 1.0550 us/op 952.00 ns/op 1.11
List(uint8) 100000 binary -> struct 1.5310 ms/op 1.1825 ms/op 1.29
List(uint8) 100000 binary -> tree_backed 91.247 us/op 86.720 us/op 1.05
List(uint8) 100000 struct -> tree_backed 1.1213 ms/op 1.1340 ms/op 0.99
List(uint8) 100000 tree_backed -> struct 1.0938 ms/op 1.0001 ms/op 1.09
List(uint8) 100000 struct -> binary 1.0102 ms/op 987.80 us/op 1.02
List(uint8) 100000 tree_backed -> binary 88.502 us/op 90.795 us/op 0.97
List(uint64Number) 100000 binary -> struct 1.1648 ms/op 1.2471 ms/op 0.93
List(uint64Number) 100000 binary -> tree_backed 3.0874 ms/op 3.3607 ms/op 0.92
List(uint64Number) 100000 struct -> tree_backed 4.4838 ms/op 4.7563 ms/op 0.94
List(uint64Number) 100000 tree_backed -> struct 2.0831 ms/op 2.2367 ms/op 0.93
List(uint64Number) 100000 struct -> binary 1.3755 ms/op 1.5556 ms/op 0.88
List(uint64Number) 100000 tree_backed -> binary 855.65 us/op 869.93 us/op 0.98
List(Uint64Bigint) 100000 binary -> struct 3.6245 ms/op 3.5944 ms/op 1.01
List(Uint64Bigint) 100000 binary -> tree_backed 3.3089 ms/op 3.3181 ms/op 1.00
List(Uint64Bigint) 100000 struct -> tree_backed 5.4161 ms/op 5.4001 ms/op 1.00
List(Uint64Bigint) 100000 tree_backed -> struct 4.7523 ms/op 4.8992 ms/op 0.97
List(Uint64Bigint) 100000 struct -> binary 2.0478 ms/op 2.0607 ms/op 0.99
List(Uint64Bigint) 100000 tree_backed -> binary 973.63 us/op 1.3819 ms/op 0.70
Vector(Root) 100000 binary -> struct 30.148 ms/op 30.789 ms/op 0.98
Vector(Root) 100000 binary -> tree_backed 30.464 ms/op 32.594 ms/op 0.93
Vector(Root) 100000 struct -> tree_backed 37.463 ms/op 35.251 ms/op 1.06
Vector(Root) 100000 tree_backed -> struct 44.378 ms/op 43.491 ms/op 1.02
Vector(Root) 100000 struct -> binary 2.5751 ms/op 2.6369 ms/op 0.98
Vector(Root) 100000 tree_backed -> binary 9.4577 ms/op 10.085 ms/op 0.94
List(Validator) 100000 binary -> struct 103.45 ms/op 94.057 ms/op 1.10
List(Validator) 100000 binary -> tree_backed 269.35 ms/op 291.23 ms/op 0.92
List(Validator) 100000 struct -> tree_backed 299.20 ms/op 302.31 ms/op 0.99
List(Validator) 100000 tree_backed -> struct 194.58 ms/op 197.29 ms/op 0.99
List(Validator) 100000 struct -> binary 27.174 ms/op 26.666 ms/op 1.02
List(Validator) 100000 tree_backed -> binary 99.877 ms/op 102.67 ms/op 0.97
List(Validator-NS) 100000 binary -> struct 103.03 ms/op 105.55 ms/op 0.98
List(Validator-NS) 100000 binary -> tree_backed 140.43 ms/op 144.09 ms/op 0.97
List(Validator-NS) 100000 struct -> tree_backed 167.98 ms/op 172.04 ms/op 0.98
List(Validator-NS) 100000 tree_backed -> struct 148.79 ms/op 149.45 ms/op 1.00
List(Validator-NS) 100000 struct -> binary 27.051 ms/op 26.850 ms/op 1.01
List(Validator-NS) 100000 tree_backed -> binary 32.156 ms/op 31.772 ms/op 1.01
get epochStatuses - MutableVector 95.887 us/op 91.125 us/op 1.05
get epochStatuses - ViewDU 201.28 us/op 203.25 us/op 0.99
set epochStatuses - ListTreeView 1.6520 ms/op 1.4927 ms/op 1.11
set epochStatuses - ListTreeView - set() 438.45 us/op 432.51 us/op 1.01
set epochStatuses - ListTreeView - commit() 509.17 us/op 520.98 us/op 0.98
bitstring 641.76 ns/op 636.31 ns/op 1.01
bit mask 13.534 ns/op 13.900 ns/op 0.97
struct - increase slot to 1000000 927.82 us/op 928.09 us/op 1.00
UintNumberType - increase slot to 1000000 21.701 ms/op 23.525 ms/op 0.92
UintBigintType - increase slot to 1000000 165.12 ms/op 155.34 ms/op 1.06
UintBigint8 x 100000 tree_deserialize 4.3926 ms/op 4.7437 ms/op 0.93
UintBigint8 x 100000 tree_serialize 1.0911 ms/op 1.1149 ms/op 0.98
UintBigint16 x 100000 tree_deserialize 4.4855 ms/op 4.8136 ms/op 0.93
UintBigint16 x 100000 tree_serialize 1.1512 ms/op 1.1636 ms/op 0.99
UintBigint32 x 100000 tree_deserialize 4.4575 ms/op 5.0074 ms/op 0.89
UintBigint32 x 100000 tree_serialize 1.1769 ms/op 1.1815 ms/op 1.00
UintBigint64 x 100000 tree_deserialize 5.2653 ms/op 5.2460 ms/op 1.00
UintBigint64 x 100000 tree_serialize 1.5891 ms/op 1.5897 ms/op 1.00
UintBigint8 x 100000 value_deserialize 433.79 us/op 433.00 us/op 1.00
UintBigint8 x 100000 value_serialize 584.74 us/op 595.68 us/op 0.98
UintBigint16 x 100000 value_deserialize 464.37 us/op 468.20 us/op 0.99
UintBigint16 x 100000 value_serialize 648.58 us/op 661.48 us/op 0.98
UintBigint32 x 100000 value_deserialize 436.61 us/op 433.32 us/op 1.01
UintBigint32 x 100000 value_serialize 622.95 us/op 630.69 us/op 0.99
UintBigint64 x 100000 value_deserialize 497.56 us/op 498.13 us/op 1.00
UintBigint64 x 100000 value_serialize 801.39 us/op 833.07 us/op 0.96
UintBigint8 x 100000 deserialize 3.0228 ms/op 3.0272 ms/op 1.00
UintBigint8 x 100000 serialize 1.5284 ms/op 1.4133 ms/op 1.08
UintBigint16 x 100000 deserialize 3.1257 ms/op 3.1150 ms/op 1.00
UintBigint16 x 100000 serialize 1.5031 ms/op 1.4402 ms/op 1.04
UintBigint32 x 100000 deserialize 3.1756 ms/op 3.2150 ms/op 0.99
UintBigint32 x 100000 serialize 3.2953 ms/op 2.7030 ms/op 1.22
UintBigint64 x 100000 deserialize 3.6902 ms/op 3.6790 ms/op 1.00
UintBigint64 x 100000 serialize 1.5178 ms/op 1.5052 ms/op 1.01
UintBigint128 x 100000 deserialize 5.1122 ms/op 5.2996 ms/op 0.96
UintBigint128 x 100000 serialize 14.457 ms/op 15.174 ms/op 0.95
UintBigint256 x 100000 deserialize 8.0488 ms/op 8.0697 ms/op 1.00
UintBigint256 x 100000 serialize 42.781 ms/op 45.420 ms/op 0.94
Slice from Uint8Array x25000 1.1675 ms/op 1.1276 ms/op 1.04
Slice from ArrayBuffer x25000 15.986 ms/op 16.514 ms/op 0.97
Slice from ArrayBuffer x25000 + new Uint8Array 17.288 ms/op 17.645 ms/op 0.98
Copy Uint8Array 100000 iterate 1.6538 ms/op 1.8561 ms/op 0.89
Copy Uint8Array 100000 slice 121.49 us/op 177.74 us/op 0.68
Copy Uint8Array 100000 Uint8Array.prototype.slice.call 124.11 us/op 164.50 us/op 0.75
Copy Buffer 100000 Uint8Array.prototype.slice.call 125.04 us/op 173.89 us/op 0.72
Copy Uint8Array 100000 slice + set 184.38 us/op 315.78 us/op 0.58
Copy Uint8Array 100000 subarray + set 109.75 us/op 168.51 us/op 0.65
Copy Uint8Array 100000 slice arrayBuffer 109.99 us/op 175.35 us/op 0.63
Uint64 deserialize 100000 - iterate Uint8Array 1.8522 ms/op 1.8257 ms/op 1.01
Uint64 deserialize 100000 - by Uint32A 1.8632 ms/op 1.7573 ms/op 1.06
Uint64 deserialize 100000 - by DataView.getUint32 x2 1.8740 ms/op 1.7824 ms/op 1.05
Uint64 deserialize 100000 - by DataView.getBigUint64 4.9524 ms/op 4.9919 ms/op 0.99
Uint64 deserialize 100000 - by byte 40.158 ms/op 39.996 ms/op 1.00

by benchmarkbot/action

@twoeths twoeths marked this pull request as ready for review July 23, 2024 08:55
@twoeths twoeths requested a review from a team as a code owner July 23, 2024 08:55
@g11tech
Copy link
Contributor

g11tech commented Jul 24, 2024

when it grows it only need to add one more list items, instead of allocating a whole new array to reuse and save memory

this is where it optimizes memory?

newTail.dest = dest;
} else {
// grow the list
newTail = {src0, src1, dest, next: null};
Copy link
Contributor

Choose a reason for hiding this comment

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

so this part optimizes memory over the array implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, when we are at length 1M, for example, pushing a new item cause very small allocation for LinkedList while could be a big deal for an array, especially array of objects

that's why we see a lot of 1s spikes using Array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants