ChainSafe / blst-ts

Typescript wrapper for https://github.com/supranational/blst native bindings, a highly performant BLS12-381 signature library
Other
18 stars 13 forks source link

refactor: make async/sync functions DRY #145

Closed matthewkeil closed 5 months ago

matthewkeil commented 5 months ago

Split off from #143

Motivation In order to DRY the code the two async functions were refactored so that there is only one implementation for both sync and async versions. Makes it easier to ensure that the code for both is identical and that changes made to comply with specs were applied equally. Also makes sure that only need to test sync version but with surety that the async versions will work identically.

Note No changes were made to core implementation. Only refactored to make helper functions that could be used in both the sync and async versions of each function.

Included Change

github-actions[bot] commented 5 months ago

Performance Report

✔️ no performance regression detected

Full benchmark results | Benchmark suite | Current: e9a8920d8696ddb7dfaecf749d333988f0aa6d72 | Previous: - | Ratio | |-|-|-|-| | PublicKey serialization | 957.00 ns/op | | PublicKey deserialize | 22.654 us/op | | PublicKey deserialize and validate - 1 keys | 83.423 us/op | | PublicKey deserialize and validate - 100 keys | 8.2741 ms/op | | PublicKey deserialize and validate - 10000 keys | 831.35 ms/op | | SecretKey.fromKeygen | 2.2960 us/op | | SecretKey serialization | 913.00 ns/op | | SecretKey deserialization | 1.5660 us/op | | SecretKey.toPublicKey | 138.23 us/op | | SecretKey.sign | 528.83 us/op | | Signature serialization | 1.1510 us/op | | Signature deserialize | 44.343 us/op | | Signatures deserialize and validate - 1 sets | 120.49 us/op | | Signatures deserialize and validate - 100 sets | 11.953 ms/op | | Signatures deserialize and validate - 10000 sets | 1.1975 s/op | | aggregatePublicKeys - 1 sets | 2.4910 us/op | | aggregatePublicKeys - 8 sets | 10.486 us/op | | aggregatePublicKeys - 32 sets | 37.551 us/op | | aggregatePublicKeys - 128 sets | 146.16 us/op | | aggregatePublicKeys - 256 sets | 294.25 us/op | | aggregateSignatures - 1 sets | 4.2140 us/op | | aggregateSignatures - 8 sets | 23.781 us/op | | aggregateSignatures - 32 sets | 90.876 us/op | | aggregateSignatures - 128 sets | 360.25 us/op | | aggregateSignatures - 256 sets | 726.30 us/op | | aggregateVerify - 1 sets | 1.5770 ms/op | | aggregateVerify - 8 sets | 5.7248 ms/op | | aggregateVerify - 32 sets | 20.343 ms/op | | aggregateVerify - 128 sets | 78.789 ms/op | | aggregateVerify - 256 sets | 156.55 ms/op | | verifyMultipleAggregateSignatures - 1 sets | 1.7415 ms/op | | verifyMultipleAggregateSignatures - 8 sets | 7.0462 ms/op | | verifyMultipleAggregateSignatures - 32 sets | 25.687 ms/op | | verifyMultipleAggregateSignatures - 128 sets | 99.800 ms/op | | verifyMultipleAggregateSignatures - 256 sets | 198.63 ms/op | | Same message - 1 sets | 1.7014 ms/op | | Same message - 8 sets | 2.5715 ms/op | | Same message - 32 sets | 5.5454 ms/op | | Same message - 128 sets | 17.384 ms/op | | Same message - 256 sets | 33.079 ms/op | | libuv multithreading - addVerificationRandomness true | 23.747 s/op | | libuv multithreading - addVerificationRandomness false | 23.699 s/op |

by benchmarkbot/action

matthewkeil commented 5 months ago

@LesnyRumcajs You inspired me to DRY some of these implementations up. There are lots of line changed but its mostly just a refactor. Little core functionality changed. Would you be so kind as to just look at the file structure of how I refactored.