Git Product home page Git Product logo

Comments (4)

Skycoder42 avatar Skycoder42 commented on June 30, 2024

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.

Skycoder42 avatar Skycoder42 commented on June 30, 2024

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.

hootyjeremy avatar hootyjeremy commented on June 30, 2024

Wow! Thanks a lot. I will look forward to the update.

from libsodium_dart_bindings.

hootyjeremy avatar hootyjeremy commented on June 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.