Comments (4)
Hi. So I ran your gist on my local machine and got other results. On my machine, it takes about 5 seconds to encrypt the data with secretBox or aead. However, I also ran a more detailed benchmark, checking where this time comes from. Here are the results:
Beginning sodium.crypto.secretBox.easy() ...
> validation: 0:00:00.000316
> copy data to native: 0:00:04.989121
> encryption: 0:00:00.076314
> copy data to dart: 0:00:00.068359
duration for sodium.crypto.secretBox.easy: 0:00:05.140866
So as you can see, the encryption only takes 70 milliseconds. However, the step that copies the dart bytes array to native C takes up ca. 97% of the execution time!
The weird part here is, that the same number of bytes are copied from dart -> native as are copied back! So obviously, the native -> dart does something optimized, which does not happen the other way around.
I will investigate this and try to find out, why there is such a big difference.
from libsodium_dart_bindings.
Okay, I already located the issue: I was accidentally iteration over the data array in dart as part of the copy process. I change the code to only use the built-it copy mechanisms of dart (which are optimized to use memcpy if possible) and now the times are much better:
--------------------------------------------
Beginning sodium.crypto.secretBox.easy() ...
duration for sodium.crypto.secretBox.easy: 0:00:00.192984
------------------------------------------
Beginning sodium.crypto.aead.encrypt() ...
duration for sodium.crypto.aead.encrypt: 0:00:00.247270
done
I will release a hotfix update asap, so you can test if this improves benchmarks for you as well.
from libsodium_dart_bindings.
Wow! Thanks a lot. I will look forward to the update.
from libsodium_dart_bindings.
I just tested 1.2.5 and it's finishing in ~0:00:00.186893 for encrypt and decrypt. Thanks for looking into this! Great work.
from libsodium_dart_bindings.
Related Issues (20)
- Regenerate Sign KeyPair HOT 2
- SecretStream Push method HOT 12
- How to test? HOT 2
- Upgrade to latest freezed version HOT 3
- How to set SecureKey manually? HOT 1
- Full build for Android version HOT 1
- Cannot read properties of undefined (reading 'then') HOT 2
- please update ffi HOT 2
- sodium.js - Cannot read properties of undefined (reading 'then') HOT 5
- Implement crypto_stream_xchacha20 HOT 1
- FFI failure or SodiumInit timing problem? HOT 9
- Flutter_test Failed to lookup symbol 'sodium_init' HOT 9
- Create `Sodium.runIsolated` method to easily run computation heavy cryptographic operations in an isolate HOT 12
- How does one use AES-GCM? HOT 12
- Request for SecretStream encryption/decryption example HOT 7
- Sodium.runIsolated breaking flutter run build HOT 2
- build failure: libsodium.so not found on latest update HOT 4
- Implement cryptoSignEd25519SkToSeed (crypto_sign_ed25519_sk_to_seed) HOT 8
- Cannot build on Windows HOT 14
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libsodium_dart_bindings.