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

Use allocUnsafe where possible #278

Closed
wants to merge 1 commit into from
Closed

Use allocUnsafe where possible #278

wants to merge 1 commit into from

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Sep 3, 2022

Motivation

  • allocUnsafe() is better in NodeJS environment
  • there is an external memory spike issue in lodestar

Description

  • Use allocUnsafe where possible

@render
Copy link

render bot commented Sep 3, 2022

@github-actions
Copy link

github-actions bot commented Sep 3, 2022

Performance Report

✔️ no performance regression detected

Full benchmark results
Benchmark suite Current: 17437be Previous: d030130 Ratio
digestTwoHashObjects 50023 times 57.985 ms/op 67.815 ms/op 0.86
digest64 50023 times 63.853 ms/op 71.046 ms/op 0.90
digest 50023 times 63.038 ms/op 71.343 ms/op 0.88
input length 32 1.6140 us/op 1.7780 us/op 0.91
input length 64 1.7740 us/op 1.9430 us/op 0.91
input length 128 2.9420 us/op 3.3140 us/op 0.89
input length 256 4.2020 us/op 4.8960 us/op 0.86
input length 512 6.8560 us/op 8.0070 us/op 0.86
input length 1024 13.311 us/op 15.233 us/op 0.87
digest 1000000 times 1.1079 s/op 1.1948 s/op 0.93
hashObjectToByteArray 50023 times 2.2562 ms/op 1.9415 ms/op 1.16
byteArrayToHashObject 50023 times 2.6273 ms/op 2.1827 ms/op 1.20
getGindicesAtDepth 6.7120 us/op 5.9000 us/op 1.14
iterateAtDepth 13.918 us/op 12.853 us/op 1.08
getGindexBits 678.00 ns/op 702.00 ns/op 0.97
gindexIterator 1.4180 us/op 1.5430 us/op 0.92
hash 2 Uint8Array 2250026 times 2.9140 s/op 3.2718 s/op 0.89
hashTwoObjects 2250026 times 2.6072 s/op 3.0628 s/op 0.85
getNodeH() x7812.5 avg hindex 21.599 us/op 17.873 us/op 1.21
getNodeH() x7812.5 index 0 8.2350 us/op 6.8080 us/op 1.21
getNodeH() x7812.5 index 7 8.2400 us/op 6.7510 us/op 1.22
getNodeH() x7812.5 index 7 with key array 8.2360 us/op 6.7740 us/op 1.22
new LeafNode() x7812.5 137.56 us/op 302.00 us/op 0.46
packedRootsBytesToLeafNodes bytes 4000 offset 0 3.3510 us/op 6.4230 us/op 0.52
packedRootsBytesToLeafNodes bytes 4000 offset 1 3.3350 us/op 6.4030 us/op 0.52
packedRootsBytesToLeafNodes bytes 4000 offset 2 3.3270 us/op 6.4810 us/op 0.51
packedRootsBytesToLeafNodes bytes 4000 offset 3 3.3230 us/op 6.4240 us/op 0.52
subtreeFillToContents depth 40 count 250000 76.076 ms/op 65.424 ms/op 1.16
setRoot - gindexBitstring 13.928 ms/op 11.363 ms/op 1.23
setRoot - gindex 14.194 ms/op 11.984 ms/op 1.18
getRoot - gindexBitstring 4.0173 ms/op 2.7342 ms/op 1.47
getRoot - gindex 4.7682 ms/op 3.0997 ms/op 1.54
getHashObject then setHashObject 15.958 ms/op 13.626 ms/op 1.17
setNodeWithFn 14.116 ms/op 12.427 ms/op 1.14
getNodeAtDepth depth 0 x100000 2.0680 ms/op 1.7755 ms/op 1.16
setNodeAtDepth depth 0 x100000 4.2232 ms/op 3.5016 ms/op 1.21
getNodesAtDepth depth 0 x100000 1.7870 ms/op 1.4290 ms/op 1.25
setNodesAtDepth depth 0 x100000 2.2981 ms/op 1.9070 ms/op 1.21
getNodeAtDepth depth 1 x100000 2.1577 ms/op 1.8312 ms/op 1.18
setNodeAtDepth depth 1 x100000 9.1210 ms/op 7.5030 ms/op 1.22
getNodesAtDepth depth 1 x100000 1.9154 ms/op 1.5403 ms/op 1.24
setNodesAtDepth depth 1 x100000 7.2436 ms/op 6.1734 ms/op 1.17
getNodeAtDepth depth 2 x100000 2.6782 ms/op 2.3889 ms/op 1.12
setNodeAtDepth depth 2 x100000 16.008 ms/op 12.683 ms/op 1.26
getNodesAtDepth depth 2 x100000 10.103 ms/op 8.2884 ms/op 1.22
setNodesAtDepth depth 2 x100000 22.530 ms/op 20.675 ms/op 1.09
tree.getNodesAtDepth - gindexes 8.5864 ms/op 6.0811 ms/op 1.41
tree.getNodesAtDepth - push all nodes 2.7030 ms/op 2.3678 ms/op 1.14
tree.getNodesAtDepth - navigation 335.51 us/op 201.45 us/op 1.67
tree.setNodesAtDepth - indexes 576.27 us/op 512.95 us/op 1.12
set at depth 8 972.00 ns/op 848.00 ns/op 1.15
set at depth 16 947.00 ns/op 975.00 ns/op 0.97
set at depth 32 1.8160 us/op 1.5930 us/op 1.14
iterateNodesAtDepth 8 256 21.692 us/op 18.668 us/op 1.16
getNodesAtDepth 8 256 5.4070 us/op 4.2760 us/op 1.26
iterateNodesAtDepth 16 65536 6.4315 ms/op 5.4861 ms/op 1.17
getNodesAtDepth 16 65536 2.4702 ms/op 2.1105 ms/op 1.17
iterateNodesAtDepth 32 250000 23.799 ms/op 20.055 ms/op 1.19
getNodesAtDepth 32 250000 7.0117 ms/op 5.1933 ms/op 1.35
iterateNodesAtDepth 40 250000 23.818 ms/op 20.434 ms/op 1.17
getNodesAtDepth 40 250000 7.0145 ms/op 5.1401 ms/op 1.36
250k validators 3.1272 s/op 3.5022 s/op 0.89
bitlist bytes to struct (120,90) 1.5110 us/op 1.3230 us/op 1.14
bitlist bytes to tree (120,90) 5.9030 us/op 5.2250 us/op 1.13
bitlist bytes to struct (2048,2048) 2.3350 us/op 2.0240 us/op 1.15
bitlist bytes to tree (2048,2048) 9.2060 us/op 8.2350 us/op 1.12
ByteListType - deserialize 19.226 ms/op 17.217 ms/op 1.12
BasicListType - deserialize 29.803 ms/op 26.447 ms/op 1.13
ByteListType - serialize 18.591 ms/op 16.693 ms/op 1.11
BasicListType - serialize 23.659 ms/op 21.590 ms/op 1.10
BasicListType - tree_convertToStruct 58.509 ms/op 47.857 ms/op 1.22
List[uint8, 68719476736] len 300000 ViewDU.getAll() + iterate 6.0196 ms/op 5.1069 ms/op 1.18
List[uint8, 68719476736] len 300000 ViewDU.get(i) 6.1678 ms/op 4.1674 ms/op 1.48
Array.push len 300000 empty Array - number 8.5414 ms/op 6.5881 ms/op 1.30
Array.set len 300000 from new Array - number 2.8014 ms/op 2.3865 ms/op 1.17
Array.set len 300000 - number 8.7935 ms/op 6.6139 ms/op 1.33
Uint8Array.set len 300000 300.62 us/op 282.10 us/op 1.07
Uint32Array.set len 300000 572.57 us/op 333.11 us/op 1.72
Container({a: uint8, b: uint8}) getViewDU x300000 41.726 ms/op 33.840 ms/op 1.23
ContainerNodeStruct({a: uint8, b: uint8}) getViewDU x300000 14.895 ms/op 13.502 ms/op 1.10
List(Container) len 300000 ViewDU.getAllReadonly() + iterate 353.81 ms/op 284.72 ms/op 1.24
List(Container) len 300000 ViewDU.getAllReadonlyValues() + iterate 420.62 ms/op 362.39 ms/op 1.16
List(Container) len 300000 ViewDU.get(i) 10.762 ms/op 9.6377 ms/op 1.12
List(Container) len 300000 ViewDU.getReadonly(i) 10.549 ms/op 8.9337 ms/op 1.18
List(ContainerNodeStruct) len 300000 ViewDU.getAllReadonly() + iterate 63.441 ms/op 52.213 ms/op 1.22
List(ContainerNodeStruct) len 300000 ViewDU.getAllReadonlyValues() + iterate 10.089 ms/op 6.5095 ms/op 1.55
List(ContainerNodeStruct) len 300000 ViewDU.get(i) 9.8967 ms/op 8.9663 ms/op 1.10
List(ContainerNodeStruct) len 300000 ViewDU.getReadonly(i) 10.283 ms/op 8.5247 ms/op 1.21
Array.push len 300000 empty Array - object 8.5379 ms/op 6.4702 ms/op 1.32
Array.set len 300000 from new Array - object 2.5576 ms/op 2.3033 ms/op 1.11
Array.set len 300000 - object 8.4201 ms/op 5.9278 ms/op 1.42
cachePermanentRootStruct no cache 12.124 us/op 12.866 us/op 0.94
cachePermanentRootStruct with cache 441.00 ns/op 455.00 ns/op 0.97
epochParticipation len 250000 rws 7813 3.2291 ms/op 3.1717 ms/op 1.02
deserialize Attestation - tree 4.4160 us/op 4.3480 us/op 1.02
deserialize Attestation - struct 3.6080 us/op 2.8530 us/op 1.26
deserialize SignedAggregateAndProof - tree 5.1160 us/op 5.1130 us/op 1.00
deserialize SignedAggregateAndProof - struct 5.5300 us/op 4.4710 us/op 1.24
deserialize SyncCommitteeMessage - tree 1.5530 us/op 1.8050 us/op 0.86
deserialize SyncCommitteeMessage - struct 1.9370 us/op 1.7630 us/op 1.10
deserialize SignedContributionAndProof - tree 2.9810 us/op 3.1980 us/op 0.93
deserialize SignedContributionAndProof - struct 4.3350 us/op 3.5300 us/op 1.23
deserialize SignedBeaconBlock - tree 326.36 us/op 317.51 us/op 1.03
deserialize SignedBeaconBlock - struct 258.01 us/op 180.10 us/op 1.43
BeaconState vc 300000 - deserialize tree 949.54 ms/op 728.31 ms/op 1.30
BeaconState vc 300000 - serialize tree 310.77 ms/op 244.79 ms/op 1.27
BeaconState.historicalRoots vc 300000 - deserialize tree 1.1300 us/op 1.2180 us/op 0.93
BeaconState.historicalRoots vc 300000 - serialize tree 1.5290 us/op 1.4130 us/op 1.08
BeaconState.validators vc 300000 - deserialize tree 937.56 ms/op 673.17 ms/op 1.39
BeaconState.validators vc 300000 - serialize tree 235.50 ms/op 183.64 ms/op 1.28
BeaconState.balances vc 300000 - deserialize tree 37.278 ms/op 27.836 ms/op 1.34
BeaconState.balances vc 300000 - serialize tree 5.0601 ms/op 3.6197 ms/op 1.40
BeaconState.previousEpochParticipation vc 300000 - deserialize tree 652.33 us/op 481.53 us/op 1.35
BeaconState.previousEpochParticipation vc 300000 - serialize tree 488.53 us/op 357.99 us/op 1.36
BeaconState.currentEpochParticipation vc 300000 - deserialize tree 659.46 us/op 488.64 us/op 1.35
BeaconState.currentEpochParticipation vc 300000 - serialize tree 485.63 us/op 354.90 us/op 1.37
BeaconState.inactivityScores vc 300000 - deserialize tree 38.624 ms/op 33.428 ms/op 1.16
BeaconState.inactivityScores vc 300000 - serialize tree 5.3291 ms/op 3.6050 ms/op 1.48
hashTreeRoot Attestation - struct 37.650 us/op 41.278 us/op 0.91
hashTreeRoot Attestation - tree 27.148 us/op 28.929 us/op 0.94
hashTreeRoot SignedAggregateAndProof - struct 57.982 us/op 61.647 us/op 0.94
hashTreeRoot SignedAggregateAndProof - tree 41.964 us/op 43.934 us/op 0.96
hashTreeRoot SyncCommitteeMessage - struct 12.648 us/op 13.574 us/op 0.93
hashTreeRoot SyncCommitteeMessage - tree 8.9520 us/op 9.9360 us/op 0.90
hashTreeRoot SignedContributionAndProof - struct 35.226 us/op 38.067 us/op 0.93
hashTreeRoot SignedContributionAndProof - tree 26.331 us/op 29.856 us/op 0.88
hashTreeRoot SignedBeaconBlock - struct 3.1743 ms/op 3.4140 ms/op 0.93
hashTreeRoot SignedBeaconBlock - tree 2.4065 ms/op 2.7735 ms/op 0.87
hashTreeRoot Validator - struct 17.395 us/op 17.222 us/op 1.01
hashTreeRoot Validator - tree 15.642 us/op 16.925 us/op 0.92
BeaconState vc 300000 - hashTreeRoot tree 4.9986 s/op 5.5232 s/op 0.91
BeaconState.historicalRoots vc 300000 - hashTreeRoot tree 2.3490 us/op 2.4650 us/op 0.95
BeaconState.validators vc 300000 - hashTreeRoot tree 4.7616 s/op 5.2805 s/op 0.90
BeaconState.balances vc 300000 - hashTreeRoot tree 119.04 ms/op 132.23 ms/op 0.90
BeaconState.previousEpochParticipation vc 300000 - hashTreeRoot tree 12.461 ms/op 14.427 ms/op 0.86
BeaconState.currentEpochParticipation vc 300000 - hashTreeRoot tree 12.464 ms/op 14.416 ms/op 0.86
BeaconState.inactivityScores vc 300000 - hashTreeRoot tree 130.18 ms/op 140.62 ms/op 0.93
hash64 x18 24.209 us/op 27.409 us/op 0.88
hashTwoObjects x18 23.990 us/op 27.494 us/op 0.87
hash64 x1740 2.2918 ms/op 2.5413 ms/op 0.90
hashTwoObjects x1740 2.2468 ms/op 2.5977 ms/op 0.86
hash64 x2700000 3.5559 s/op 3.9509 s/op 0.90
hashTwoObjects x2700000 3.4873 s/op 4.0055 s/op 0.87
get_exitEpoch - ContainerType 427.00 ns/op 479.00 ns/op 0.89
get_exitEpoch - ContainerNodeStructType 417.00 ns/op 415.00 ns/op 1.00
set_exitEpoch - ContainerType 471.00 ns/op 486.00 ns/op 0.97
set_exitEpoch - ContainerNodeStructType 447.00 ns/op 432.00 ns/op 1.03
get_pubkey - ContainerType 1.8660 us/op 1.7610 us/op 1.06
get_pubkey - ContainerNodeStructType 446.00 ns/op 454.00 ns/op 0.98
hashTreeRoot - ContainerType 818.00 ns/op 943.00 ns/op 0.87
hashTreeRoot - ContainerNodeStructType 850.00 ns/op 989.00 ns/op 0.86
createProof - ContainerType 7.0710 us/op 7.4960 us/op 0.94
createProof - ContainerNodeStructType 36.767 us/op 35.206 us/op 1.04
serialize - ContainerType 2.8610 us/op 2.9370 us/op 0.97
serialize - ContainerNodeStructType 2.9630 us/op 2.3920 us/op 1.24
set_exitEpoch_and_hashTreeRoot - ContainerType 6.5140 us/op 6.8490 us/op 0.95
set_exitEpoch_and_hashTreeRoot - ContainerNodeStructType 17.136 us/op 17.756 us/op 0.97
Array - for of 10.757 us/op 7.0400 us/op 1.53
Array - for(;;) 7.3900 us/op 6.6690 us/op 1.11
basicListValue.readonlyValuesArray() 7.6292 ms/op 5.6039 ms/op 1.36
basicListValue.readonlyValuesArray() + loop all 7.3373 ms/op 5.3216 ms/op 1.38
compositeListValue.readonlyValuesArray() 44.505 ms/op 38.637 ms/op 1.15
compositeListValue.readonlyValuesArray() + loop all 40.260 ms/op 38.540 ms/op 1.04
Number64UintType - get balances list 1.7076 ms/op 1.4975 ms/op 1.14
Number64UintType - set balances list 13.537 ms/op 13.084 ms/op 1.03
Number64UintType - get and increase 10 then set 49.563 ms/op 40.621 ms/op 1.22
Number64UintType - increase 10 using applyDelta 17.491 ms/op 16.043 ms/op 1.09
Number64UintType - increase 10 using applyDeltaInBatch 17.430 ms/op 16.083 ms/op 1.08
tree_newTreeFromUint64Deltas 36.323 ms/op 21.570 ms/op 1.68
unsafeUint8ArrayToTree 46.246 ms/op 42.689 ms/op 1.08
bitLength(50) 475.00 ns/op 502.00 ns/op 0.95
bitLengthStr(50) 660.00 ns/op 711.00 ns/op 0.93
bitLength(8000) 461.00 ns/op 482.00 ns/op 0.96
bitLengthStr(8000) 809.00 ns/op 904.00 ns/op 0.89
bitLength(250000) 466.00 ns/op 488.00 ns/op 0.95
bitLengthStr(250000) 891.00 ns/op 990.00 ns/op 0.90
floor - Math.floor (53) 0.67025 ns/op 0.60302 ns/op 1.11
floor - << 0 (53) 0.67026 ns/op 0.60303 ns/op 1.11
floor - Math.floor (512) 0.67307 ns/op 0.60287 ns/op 1.12
floor - << 0 (512) 0.66986 ns/op 0.60279 ns/op 1.11
fnIf(0) 2.6775 ns/op 2.0081 ns/op 1.33
fnSwitch(0) 3.6849 ns/op 2.4623 ns/op 1.50
fnObj(0) 0.66984 ns/op 0.60294 ns/op 1.11
fnArr(0) 0.66977 ns/op 0.60276 ns/op 1.11
fnIf(4) 4.3513 ns/op 3.1234 ns/op 1.39
fnSwitch(4) 5.0218 ns/op 3.6236 ns/op 1.39
fnObj(4) 0.67154 ns/op 0.60289 ns/op 1.11
fnArr(4) 0.67022 ns/op 0.60276 ns/op 1.11
fnIf(9) 6.6972 ns/op 5.6742 ns/op 1.18
fnSwitch(9) 6.6953 ns/op 5.6223 ns/op 1.19
fnObj(9) 0.67003 ns/op 0.60295 ns/op 1.11
fnArr(9) 0.66992 ns/op 0.60270 ns/op 1.11
Container {a,b,vec} - as struct x100000 67.450 us/op 60.695 us/op 1.11
Container {a,b,vec} - as tree x100000 703.37 us/op 573.56 us/op 1.23
Container {a,vec,b} - as struct x100000 101.78 us/op 120.91 us/op 0.84
Container {a,vec,b} - as tree x100000 803.70 us/op 632.45 us/op 1.27
get 2 props x1000000 - rawObject 335.16 us/op 401.95 us/op 0.83
get 2 props x1000000 - proxy 118.16 ms/op 99.305 ms/op 1.19
get 2 props x1000000 - customObj 335.19 us/op 402.21 us/op 0.83
Simple object binary -> struct 905.00 ns/op 1.0800 us/op 0.84
Simple object binary -> tree_backed 2.4260 us/op 2.8520 us/op 0.85
Simple object struct -> tree_backed 3.2390 us/op 3.6650 us/op 0.88
Simple object tree_backed -> struct 2.7900 us/op 3.1640 us/op 0.88
Simple object struct -> binary 1.4460 us/op 1.5590 us/op 0.93
Simple object tree_backed -> binary 2.5190 us/op 2.7580 us/op 0.91
aggregationBits binary -> struct 891.00 ns/op 889.00 ns/op 1.00
aggregationBits binary -> tree_backed 3.1640 us/op 3.0900 us/op 1.02
aggregationBits struct -> tree_backed 4.0160 us/op 3.7140 us/op 1.08
aggregationBits tree_backed -> struct 1.6960 us/op 1.6260 us/op 1.04
aggregationBits struct -> binary 1.2500 us/op 1.2810 us/op 0.98
aggregationBits tree_backed -> binary 1.5150 us/op 1.6640 us/op 0.91
List(uint8) 100000 binary -> struct 1.9442 ms/op 1.9137 ms/op 1.02
List(uint8) 100000 binary -> tree_backed 162.89 us/op 148.27 us/op 1.10
List(uint8) 100000 struct -> tree_backed 2.1202 ms/op 1.6830 ms/op 1.26
List(uint8) 100000 tree_backed -> struct 1.5468 ms/op 1.0239 ms/op 1.51
List(uint8) 100000 struct -> binary 1.9609 ms/op 1.4103 ms/op 1.39
List(uint8) 100000 tree_backed -> binary 139.74 us/op 91.856 us/op 1.52
List(uint64Number) 100000 binary -> struct 1.6628 ms/op 1.3297 ms/op 1.25
List(uint64Number) 100000 binary -> tree_backed 4.4881 ms/op 3.3702 ms/op 1.33
List(uint64Number) 100000 struct -> tree_backed 7.6486 ms/op 5.4508 ms/op 1.40
List(uint64Number) 100000 tree_backed -> struct 3.1919 ms/op 2.4562 ms/op 1.30
List(uint64Number) 100000 struct -> binary 2.5792 ms/op 1.8599 ms/op 1.39
List(uint64Number) 100000 tree_backed -> binary 1.6172 ms/op 1.0584 ms/op 1.53
List(Uint64Bigint) 100000 binary -> struct 5.3518 ms/op 4.6276 ms/op 1.16
List(Uint64Bigint) 100000 binary -> tree_backed 5.2962 ms/op 3.7550 ms/op 1.41
List(Uint64Bigint) 100000 struct -> tree_backed 8.7698 ms/op 6.9735 ms/op 1.26
List(Uint64Bigint) 100000 tree_backed -> struct 6.7082 ms/op 5.3844 ms/op 1.25
List(Uint64Bigint) 100000 struct -> binary 3.1296 ms/op 2.4826 ms/op 1.26
List(Uint64Bigint) 100000 tree_backed -> binary 1.3971 ms/op 1.1733 ms/op 1.19
Vector(Root) 100000 binary -> struct 63.855 ms/op 40.400 ms/op 1.58
Vector(Root) 100000 binary -> tree_backed 46.284 ms/op 41.073 ms/op 1.13
Vector(Root) 100000 struct -> tree_backed 60.876 ms/op 50.198 ms/op 1.21
Vector(Root) 100000 tree_backed -> struct 83.538 ms/op 59.610 ms/op 1.40
Vector(Root) 100000 struct -> binary 2.9108 ms/op 2.1747 ms/op 1.34
Vector(Root) 100000 tree_backed -> binary 13.575 ms/op 11.601 ms/op 1.17
List(Validator) 100000 binary -> struct 184.98 ms/op 142.12 ms/op 1.30
List(Validator) 100000 binary -> tree_backed 434.22 ms/op 377.50 ms/op 1.15
List(Validator) 100000 struct -> tree_backed 502.54 ms/op 433.12 ms/op 1.16
List(Validator) 100000 tree_backed -> struct 310.56 ms/op 231.58 ms/op 1.34
List(Validator) 100000 struct -> binary 44.871 ms/op 40.351 ms/op 1.11
List(Validator) 100000 tree_backed -> binary 118.56 ms/op 101.13 ms/op 1.17
List(Validator-NS) 100000 binary -> struct 199.06 ms/op 139.05 ms/op 1.43
List(Validator-NS) 100000 binary -> tree_backed 248.39 ms/op 179.90 ms/op 1.38
List(Validator-NS) 100000 struct -> tree_backed 325.31 ms/op 241.56 ms/op 1.35
List(Validator-NS) 100000 tree_backed -> struct 283.60 ms/op 216.35 ms/op 1.31
List(Validator-NS) 100000 struct -> binary 45.368 ms/op 39.962 ms/op 1.14
List(Validator-NS) 100000 tree_backed -> binary 49.542 ms/op 47.789 ms/op 1.04
get epochStatuses - MutableVector 127.03 us/op 102.75 us/op 1.24
get epochStatuses - ViewDU 290.42 us/op 259.51 us/op 1.12
set epochStatuses - ListTreeView 2.1458 ms/op 2.1002 ms/op 1.02
set epochStatuses - ListTreeView - set() 638.79 us/op 609.19 us/op 1.05
set epochStatuses - ListTreeView - commit() 760.63 us/op 670.43 us/op 1.13
bitstring 812.73 ns/op 930.04 ns/op 0.87
bit mask 23.159 ns/op 26.507 ns/op 0.87
struct - increase slot to 1000000 2.1856 ms/op 2.3590 ms/op 0.93
UintNumberType - increase slot to 1000000 41.451 ms/op 32.142 ms/op 1.29
UintBigintType - increase slot to 1000000 661.66 ms/op 642.75 ms/op 1.03
UintBigint8 x 100000 tree_deserialize 6.2803 ms/op 5.8589 ms/op 1.07
UintBigint8 x 100000 tree_serialize 2.1097 ms/op 711.67 us/op 2.96
UintBigint16 x 100000 tree_deserialize 6.2982 ms/op 6.3911 ms/op 0.99
UintBigint16 x 100000 tree_serialize 1.6178 ms/op 1.5761 ms/op 1.03
UintBigint32 x 100000 tree_deserialize 7.4782 ms/op 7.1650 ms/op 1.04
UintBigint32 x 100000 tree_serialize 1.7429 ms/op 1.5365 ms/op 1.13
UintBigint64 x 100000 tree_deserialize 9.4546 ms/op 8.4916 ms/op 1.11
UintBigint64 x 100000 tree_serialize 2.5364 ms/op 2.1518 ms/op 1.18
UintBigint8 x 100000 value_deserialize 803.85 us/op 527.05 us/op 1.53
UintBigint8 x 100000 value_serialize 1.2123 ms/op 943.56 us/op 1.28
UintBigint16 x 100000 value_deserialize 838.62 us/op 561.92 us/op 1.49
UintBigint16 x 100000 value_serialize 1.2655 ms/op 979.33 us/op 1.29
UintBigint32 x 100000 value_deserialize 736.81 us/op 541.53 us/op 1.36
UintBigint32 x 100000 value_serialize 1.2718 ms/op 971.23 us/op 1.31
UintBigint64 x 100000 value_deserialize 813.80 us/op 612.06 us/op 1.33
UintBigint64 x 100000 value_serialize 1.4729 ms/op 1.2284 ms/op 1.20
UintBigint8 x 100000 deserialize 8.6041 ms/op 6.8483 ms/op 1.26
UintBigint8 x 100000 serialize 2.1805 ms/op 2.1860 ms/op 1.00
UintBigint16 x 100000 deserialize 8.0923 ms/op 6.5021 ms/op 1.24
UintBigint16 x 100000 serialize 2.2583 ms/op 2.2093 ms/op 1.02
UintBigint32 x 100000 deserialize 8.5678 ms/op 7.2428 ms/op 1.18
UintBigint32 x 100000 serialize 4.6893 ms/op 4.0847 ms/op 1.15
UintBigint64 x 100000 deserialize 6.0076 ms/op 4.6040 ms/op 1.30
UintBigint64 x 100000 serialize 2.2346 ms/op 1.7914 ms/op 1.25
UintBigint128 x 100000 deserialize 8.6547 ms/op 6.7877 ms/op 1.28
UintBigint128 x 100000 serialize 24.147 ms/op 18.647 ms/op 1.29
UintBigint256 x 100000 deserialize 16.101 ms/op 13.600 ms/op 1.18
UintBigint256 x 100000 serialize 75.504 ms/op 67.353 ms/op 1.12
Slice from Uint8Array x25000 1.4539 ms/op 1.1330 ms/op 1.28
Slice from ArrayBuffer x25000 29.080 ms/op 27.277 ms/op 1.07
Slice from ArrayBuffer x25000 + new Uint8Array 30.555 ms/op 26.646 ms/op 1.15
Copy Uint8Array 100000 iterate 1.0618 ms/op 1.0300 ms/op 1.03
Copy Uint8Array 100000 slice 109.35 us/op 88.042 us/op 1.24
Copy Uint8Array 100000 Uint8Array.prototype.slice.call 110.10 us/op 88.462 us/op 1.24
Copy Buffer 100000 Uint8Array.prototype.slice.call 111.50 us/op 89.239 us/op 1.25
Copy Uint8Array 100000 slice + set 267.37 us/op 186.80 us/op 1.43
Copy Uint8Array 100000 subarray + set 112.18 us/op 87.573 us/op 1.28
Copy Uint8Array 100000 slice arrayBuffer 117.71 us/op 88.803 us/op 1.33
Uint64 deserialize 100000 - iterate Uint8Array 2.3751 ms/op 1.8207 ms/op 1.30
Uint64 deserialize 100000 - by Uint32A 2.1984 ms/op 1.7018 ms/op 1.29
Uint64 deserialize 100000 - by DataView.getUint32 x2 2.2504 ms/op 1.6730 ms/op 1.35
Uint64 deserialize 100000 - by DataView.getBigUint64 7.0072 ms/op 6.0223 ms/op 1.16
Uint64 deserialize 100000 - by byte 69.449 ms/op 72.310 ms/op 0.96

by benchmarkbot/action

@jeluard
Copy link

jeluard commented Feb 28, 2024

@tuyennhv this looks useful, wondering if that is still relevant?
Might be worth relying on unint8arrays alloc for this. Also, we might want to consider their pattern of converting back to Uint8Array to reduce Buffer inconsistencies.

@philknows
Copy link
Member

Bumping for update @twoeths

@twoeths
Copy link
Contributor Author

twoeths commented Oct 9, 2024

the idea was implemented for as-sha256 in #391
for ssz, we gonna reuse memory a lot in the batch hash work so it's not necessary anymore
will work on this idea for persistent-merkle-tree and lodestar

@twoeths twoeths closed this Oct 9, 2024
@twoeths twoeths deleted the tuyen/allocUnsafe branch October 9, 2024 02:28
@twoeths
Copy link
Contributor Author

twoeths commented Oct 15, 2024

allocUnsafe() in ssz is implemented in #409

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.

3 participants