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

Convert as-sha256 to typescript #244

Merged
merged 14 commits into from
Mar 23, 2022
Merged

Convert as-sha256 to typescript #244

merged 14 commits into from
Mar 23, 2022

Conversation

wemeetagain
Copy link
Member

Motivation

Remove vanilla js from the codebase

Description

Resolve #243

@wemeetagain wemeetagain marked this pull request as draft March 18, 2022 15:21
@dapplion
Copy link
Contributor

🎉

@github-actions
Copy link

github-actions bot commented Mar 23, 2022

Performance Report

✔️ no performance regression detected

🚀🚀 Significant benchmark improvement detected

Benchmark suite Current: 42afe7e Previous: 33b3cd6 Ratio
ByteListType - deserialize 2.1262 ms/op 15.905 ms/op 0.13
BasicListType - deserialize 53.455 ms/op 637.88 ms/op 0.08
ByteListType - tree_convertToStruct 74.064 ms/op 690.07 ms/op 0.11
BasicListType - tree_convertToStruct 200.07 ms/op 3.5602 s/op 0.06
Full benchmark results
Benchmark suite Current: 42afe7e Previous: 33b3cd6 Ratio
digestTwoHashObjects 50023 times 56.982 ms/op
digest64 50023 times 59.074 ms/op
digest 50023 times 59.036 ms/op
input length 32 1.6240 us/op
input length 64 1.7170 us/op
input length 128 2.9420 us/op
input length 256 4.2650 us/op
input length 512 6.9380 us/op
input length 1024 13.176 us/op
digest 1000000 times 1.0330 s/op
hashObjectToByteArray 50023 times 2.2386 ms/op
byteArrayToHashObject 50023 times 2.4860 ms/op
bitlist bytes to struct (120,90) 30.561 us/op 31.785 us/op 0.96
bitlist bytes to tree (120,90) 2.3750 us/op 2.3110 us/op 1.03
bitlist bytes to struct (2048,2048) 523.75 us/op 544.14 us/op 0.96
bitlist bytes to tree (2048,2048) 7.6830 us/op 7.2410 us/op 1.06
ByteListType - deserialize 2.1262 ms/op 15.905 ms/op 0.13
BasicListType - deserialize 53.455 ms/op 637.88 ms/op 0.08
ByteListType - serialize 31.361 ms/op 77.494 ms/op 0.40
BasicListType - serialize 30.119 ms/op 78.381 ms/op 0.38
ByteListType - tree_convertToStruct 74.064 ms/op 690.07 ms/op 0.11
BasicListType - tree_convertToStruct 200.07 ms/op 3.5602 s/op 0.06
deserialize Attestation - struct 39.019 us/op 39.514 us/op 0.99
deserialize Attestation - tree 13.425 us/op 13.586 us/op 0.99
deserialize SignedAggregateAndProof - struct 49.952 us/op 51.352 us/op 0.97
deserialize SignedAggregateAndProof - tree 18.253 us/op 18.812 us/op 0.97
deserialize SignedContributionAndProof - struct 37.510 us/op 39.052 us/op 0.96
BeaconState vc 300000 - deserialize tree 4.0961 s/op 4.4598 s/op 0.92
BeaconState vc 300000 - serialize tree 929.67 ms/op 932.37 ms/op 1.00
BeaconState.historicalRoots vc 300000 - deserialize tree 1.2120 us/op 1.2000 us/op 1.01
BeaconState.historicalRoots vc 300000 - serialize tree 4.0480 us/op 4.1320 us/op 0.98
BeaconState.validators vc 300000 - deserialize tree 3.3811 s/op 3.6164 s/op 0.93
BeaconState.validators vc 300000 - serialize tree 837.84 ms/op 832.85 ms/op 1.01
BeaconState.balances vc 300000 - deserialize tree 207.17 ms/op 225.86 ms/op 0.92
BeaconState.balances vc 300000 - serialize tree 27.869 ms/op 28.111 ms/op 0.99
BeaconState.previousEpochParticipation vc 300000 - deserialize tree 25.526 ms/op 28.279 ms/op 0.90
BeaconState.previousEpochParticipation vc 300000 - serialize tree 1.5419 ms/op 1.6129 ms/op 0.96
BeaconState.currentEpochParticipation vc 300000 - deserialize tree 25.213 ms/op 27.924 ms/op 0.90
BeaconState.currentEpochParticipation vc 300000 - serialize tree 1.5194 ms/op 1.5638 ms/op 0.97
BeaconState.inactivityScores vc 300000 - deserialize tree 211.29 ms/op 237.48 ms/op 0.89
BeaconState.inactivityScores vc 300000 - serialize tree 27.921 ms/op 28.494 ms/op 0.98
epochParticipation len 250000 rws 7813 23.895 ms/op 25.219 ms/op 0.95
Array - for of 10.493 us/op 10.532 us/op 1.00
Array - for(;;) 7.1990 us/op 7.1820 us/op 1.00
basicListValue.readonlyValues() 219.06 ms/op 220.39 ms/op 0.99
basicListValue.readonlyValuesArray() 197.22 ms/op 192.32 ms/op 1.03
basicListValue.readonlyValues() + iterate all 211.63 ms/op 211.52 ms/op 1.00
basicListValue.readonlyValuesArray() + loop all 196.66 ms/op 192.37 ms/op 1.02
compositeListValue.readonlyValues() 226.80 ms/op 239.36 ms/op 0.95
compositeListValue.readonlyValuesArray() 238.33 ms/op 241.34 ms/op 0.99
compositeListValue.readonlyValues() + iterate all 150.85 ms/op 160.91 ms/op 0.94
compositeListValue.readonlyValuesArray() + loop all 218.14 ms/op 223.84 ms/op 0.97
NumberUintType - get balances list 761.95 ms/op 766.03 ms/op 0.99
Number64UintType - get balances list 446.70 ms/op 439.44 ms/op 1.02
NumberUintType - set balances list 989.14 ms/op 1.0670 s/op 0.93
Number64UintType - set balances list 819.27 ms/op 888.93 ms/op 0.92
Number64UintType - get and increase 10 then set 1.2703 s/op 1.3272 s/op 0.96
Number64UintType - increase 10 using applyDelta 477.91 ms/op 509.13 ms/op 0.94
Number64UintType - increase 10 using applyDeltaInBatch 484.43 ms/op 519.22 ms/op 0.93
tree_newTreeFromUint64Deltas 43.150 ms/op 49.755 ms/op 0.87
unsafeUint8ArrayToTree 50.708 ms/op 51.683 ms/op 0.98
Container {a,b,vec} - as struct x100000 50.837 us/op 50.782 us/op 1.00
Container {a,b,vec} - as tree x100000 100.70 ms/op 98.768 ms/op 1.02
Container {a,vec,b} - as struct x100000 101.85 us/op 101.03 us/op 1.01
Container {a,vec,b} - as tree x100000 99.547 ms/op 98.625 ms/op 1.01
Simple object binary -> struct 2.0360 us/op 2.1020 us/op 0.97
Simple object binary -> tree_backed 3.2580 us/op 3.4790 us/op 0.94
Simple object struct -> tree_backed 1.8480 us/op 1.8800 us/op 0.98
Simple object tree_backed -> struct 2.3780 us/op 2.5120 us/op 0.95
Simple object struct -> binary 2.1360 us/op 2.3990 us/op 0.89
Simple object tree_backed -> binary 2.4720 us/op 2.6490 us/op 0.93
aggregationBits binary -> struct 33.665 us/op 34.321 us/op 0.98
aggregationBits binary -> tree_backed 2.4180 us/op 2.3460 us/op 1.03
aggregationBits struct -> tree_backed 5.0220 us/op 5.1720 us/op 0.97
aggregationBits tree_backed -> struct 5.6010 us/op 5.6910 us/op 0.98
aggregationBits struct -> binary 3.8750 us/op 4.1000 us/op 0.95
aggregationBits tree_backed -> binary 4.2000 us/op 4.2870 us/op 0.98
List(uint8) 100000 binary -> struct 8.6933 ms/op 8.6904 ms/op 1.00
List(uint8) 100000 binary -> tree_backed 4.1446 ms/op 4.1329 ms/op 1.00
List(uint8) 100000 struct -> tree_backed 3.9111 ms/op 4.1154 ms/op 0.95
List(uint8) 100000 tree_backed -> struct 3.9043 ms/op 4.1563 ms/op 0.94
List(uint8) 100000 struct -> binary 625.18 us/op 689.93 us/op 0.91
List(uint8) 100000 tree_backed -> binary 492.69 us/op 490.19 us/op 1.01
List(uint64Number) 100000 binary -> struct 78.987 ms/op 79.042 ms/op 1.00
List(uint64Number) 100000 binary -> tree_backed 46.486 ms/op 48.352 ms/op 0.96
List(uint64Number) 100000 struct -> tree_backed 18.428 ms/op 19.545 ms/op 0.94
List(uint64Number) 100000 tree_backed -> struct 18.461 ms/op 19.644 ms/op 0.94
List(uint64Number) 100000 struct -> binary 2.7690 ms/op 2.7843 ms/op 0.99
List(uint64Number) 100000 tree_backed -> binary 4.3735 ms/op 4.6308 ms/op 0.94
List(Uint64Bigint) 100000 binary -> struct 45.014 ms/op 44.910 ms/op 1.00
List(Uint64Bigint) 100000 binary -> tree_backed 48.369 ms/op 50.742 ms/op 0.95
List(Uint64Bigint) 100000 struct -> tree_backed 38.429 ms/op 40.662 ms/op 0.95
List(Uint64Bigint) 100000 tree_backed -> struct 39.088 ms/op 40.629 ms/op 0.96
List(Uint64Bigint) 100000 struct -> binary 18.132 ms/op 19.476 ms/op 0.93
List(Uint64Bigint) 100000 tree_backed -> binary 4.0177 ms/op 4.8915 ms/op 0.82
Vector(Root) 100000 binary -> struct 98.547 ms/op 108.73 ms/op 0.91
Vector(Root) 100000 binary -> tree_backed 209.17 ms/op 224.80 ms/op 0.93
Vector(Root) 100000 struct -> tree_backed 186.57 ms/op 190.25 ms/op 0.98
Vector(Root) 100000 tree_backed -> struct 176.17 ms/op 178.25 ms/op 0.99
Vector(Root) 100000 struct -> binary 3.5279 ms/op 3.5054 ms/op 1.01
Vector(Root) 100000 tree_backed -> binary 70.688 ms/op 69.797 ms/op 1.01
List(Validator) 100000 binary -> struct 765.53 ms/op 791.17 ms/op 0.97
List(Validator) 100000 binary -> tree_backed 1.1871 s/op 1.2218 s/op 0.97
List(Validator) 100000 struct -> tree_backed 910.82 ms/op 940.24 ms/op 0.97
List(Validator) 100000 tree_backed -> struct 896.35 ms/op 959.74 ms/op 0.93
List(Validator) 100000 struct -> binary 180.52 ms/op 178.91 ms/op 1.01
List(Validator) 100000 tree_backed -> binary 430.96 ms/op 411.74 ms/op 1.05
List(Validator-NS) 100000 binary -> struct 761.86 ms/op 786.38 ms/op 0.97
List(Validator-NS) 100000 binary -> tree_backed 966.39 ms/op 1.0159 s/op 0.95
List(Validator-NS) 100000 struct -> tree_backed 56.885 ms/op 60.583 ms/op 0.94
List(Validator-NS) 100000 tree_backed -> struct 60.732 ms/op 58.309 ms/op 1.04
List(Validator-NS) 100000 struct -> binary 179.77 ms/op 179.33 ms/op 1.00
List(Validator-NS) 100000 tree_backed -> binary 183.59 ms/op 185.19 ms/op 0.99
struct - increase slot to 1000000 2.6799 ms/op 2.6989 ms/op 0.99
NumberUintType - increase slot to 1000000 1.2198 s/op 1.1983 s/op 1.02
Number64UintType - increase slot to 1000000 320.36 ms/op 311.46 ms/op 1.03
get_exitEpoch - ContainerType 673.00 ns/op 683.00 ns/op 0.99
get_exitEpoch - ContainerLeafNodeStructType 527.00 ns/op 544.00 ns/op 0.97
set_exitEpoch - ContainerType 741.00 ns/op 768.00 ns/op 0.96
set_exitEpoch - ContainerLeafNodeStructType 932.00 ns/op 962.00 ns/op 0.97
get_pubkey - ContainerType 1.8720 us/op 1.9750 us/op 0.95
get_pubkey - ContainerLeafNodeStructType 561.00 ns/op 581.00 ns/op 0.97
hashTreeRoot - ContainerType 739.00 ns/op 767.00 ns/op 0.96
hashTreeRoot - ContainerLeafNodeStructType 757.00 ns/op 772.00 ns/op 0.98
createProof - ContainerType 6.9010 us/op 6.9220 us/op 1.00
createProof - ContainerLeafNodeStructType 25.727 us/op 26.415 us/op 0.97
serialize - ContainerType 5.8530 us/op 5.9870 us/op 0.98
serialize - ContainerLeafNodeStructType 3.3490 us/op 3.5580 us/op 0.94
set_exitEpoch_and_hashTreeRoot - ContainerType 4.8680 us/op 4.9220 us/op 0.99
set_exitEpoch_and_hashTreeRoot - ContainerLeafNodeStructType 17.238 us/op 17.383 us/op 0.99

by benchmarkbot/action

@wemeetagain wemeetagain marked this pull request as ready for review March 23, 2022 18:57
@wemeetagain wemeetagain merged commit 9e5bd76 into master Mar 23, 2022
@wemeetagain wemeetagain deleted the dapplion/sha256-ts branch March 23, 2022 22:54
wemeetagain pushed a commit that referenced this pull request Mar 24, 2022
BREAKING CHANGE: export digest* functions as named exports

WIP

WIP

Use ts-loader

Add codegen to prebuild

Export SHA256 class

Update sha256 usage

Remove unused code

Fix sha256 usage

Tweak as-sha256 tsconfig

Remove unused files

Remove assemblyscript runtime dependency

Tweak wasm instantiation

Add dom to root tsconfig lib

Update readme
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.

Convert as-sha256 to typescript
2 participants