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: add sodium-native #161

Closed
wants to merge 6 commits into from
Closed

feat: add sodium-native #161

wants to merge 6 commits into from

Conversation

twoeths
Copy link
Contributor

@twoeths twoeths commented Jun 20, 2022

Motivation

  • Add sodium-native as a new crypto implementation

Description

stablelib decrypt x 268,550 ops/sec ±1.05% (90 runs sampled)
sodium-native decrypt x 45,880 ops/sec ±2.47% (88 runs sampled)
stablelib encrypt x 259,846 ops/sec ±0.70% (92 runs sampled)
sodium-native encrypt x 39,432 ops/sec ±3.09% (82 runs sampled)

@twoeths twoeths changed the title Add sodium-native feat: add sodium-native Jun 20, 2022

for(const {id, crypto} of [
{id: 'stablelib decrypt', crypto: stablelib},
{id: 'sodium-native decrypt', crypto: sodiumNative}
Copy link
Contributor

Choose a reason for hiding this comment

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

@tuyennhv please do benchmarks for a range of data sizes. Research what the range of paquet sizes for eth2 objects and bechmark against them, for example: [200, 500, 1000, 1e4, 1e5, 1e6]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dapplion for eth2, most of the chunk size is 0-500, per 100 chunks like that there's a big chunk size at 20000. I updated the benchmark below

@twoeths
Copy link
Contributor Author

twoeths commented Jun 22, 2022

with a NOISE_MSG_MAX_LENGTH_BYTES of 65535 I got the following result

# Buffer size stablelib (opts/sec) sodium-native (opts/sec)
decrypt 100 321,615 26,026
encrypt 100 199,691 41,907
decrypt 500 211,464 24,126
encrypt 500 93,179 38,781
decrypt 5000 43,205 18,972
encrypt 5000 13,326 29,192
decrypt 20000 12,318 13,803
encrypt 20000 3,404 15,123
decrypt 65535 3,809 6,729
encrypt 65535 1,044 5,552

for decryption, sodium-native's performance flips at a Buffer size of 20000
for encryption, sodium-native's performance flips at a Buffer size of around 3000-4000

@ShogunPanda
Copy link
Contributor

Please note that the crypto operations might not be the only meaningful metric.
Stablelib blocks the event loop as it is JS only, while sodium does not and thus the overall server concurrency might increase even for small buffers.

@twoeths
Copy link
Contributor Author

twoeths commented Jun 22, 2022

Please note that the crypto operations might not be the only meaningful metric. Stablelib blocks the event loop as it is JS only, while sodium does not and thus the overall server concurrency might increase even for small buffers.

@ShogunPanda my understanding is sodium also blocks the event loop unless it provides some async apis

@twoeths
Copy link
Contributor Author

twoeths commented Jun 23, 2022

This profile result shows that sodium-native has a lot of javascript-native communication overhead
sodium-native-prof-result.txt

@twoeths
Copy link
Contributor Author

twoeths commented Nov 16, 2022

decided to go with https://github.com/ChainSafe/as-chacha20poly1305

@twoeths twoeths closed this Nov 16, 2022
@twoeths twoeths deleted the tuyen/sodium-native branch November 16, 2022 08:33
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