Code Monkey home page Code Monkey logo

Comments (13)

dchest avatar dchest commented on July 26, 2024 1

Looks like crypto_scrypt-nosse.c is actually crypto_scrypt-ref.c, which is a slow reference implementation using 8-bit arrays. scrypt-async-js and the proper -nosse version use 32-bit arrays. I think you can replace it (with this), tweak to what cordova-plugin-scrypt/src/libscrypt/ expects and it will be much faster.

from cordova-plugin-scrypt.

ggozad avatar ggozad commented on July 26, 2024

At the time we did the plugin the only implementation was the one in sjcl which has abysmal performance. I doubt we are going to pursue optimising this further as we merely used the reference implementation and made it compile on the various platforms + bindings. That said, feel free to make a PR :)

from cordova-plugin-scrypt.

ggozad avatar ggozad commented on July 26, 2024

Still it is surprising you get such a small difference. I bet this is on android? on iOS you are going to get a lot more.
I do not think one can optimize a lot further due to the nature of scrypt too.

from cordova-plugin-scrypt.

homakov avatar homakov commented on July 26, 2024

I just run tests on ios emulator and on a real device: results are strange. On emulator scrypt plugin is much slower than scrypt js. On a real device it is a bit faster but both are painfully slow, like 120 seconds for N=2^16 p=3. Is it normal? What params do you use for your projects by the way?

from cordova-plugin-scrypt.

dchest avatar dchest commented on July 26, 2024

@homakov no, it's not normal. 3 sec in Chrome on Android (Snapdragon 650). Try this in Safari. The reason for JS slowness may be the absence of JIT compilation (I don't know about Cordova, but React Native, for example, doesn't have it due to the use of JavaScriptCore — only WKWebView has it), but I'm baffled about slow native performance. Could it be that it's an unoptimized/debug built?

from cordova-plugin-scrypt.

homakov avatar homakov commented on July 26, 2024

Ok, when you run with --release mode it is actually faster. Now for 2^18 p=10 on my macbook it takes 8 seconds while on ipad ~32. I guess compiler optimizes plugin.

Btw what about these warnings:

[329:40605] THREAD WARNING: ['ScryptPlugin'] took '1457.798828' ms. Plugin should use a background thread.

from cordova-plugin-scrypt.

ggozad avatar ggozad commented on July 26, 2024

You should benchmark on real devices. And yes --release is important there :)
The warning is what it says. It would be better (and not too hard if you want to give it a try) to run this on a thread instead.

from cordova-plugin-scrypt.

homakov avatar homakov commented on July 26, 2024

How to run in a thread? Online search tells me I'd need to change some native code. Will it make script faster? because I don't mind blocking the UI

from cordova-plugin-scrypt.

ggozad avatar ggozad commented on July 26, 2024

Yes this would need to be done on the plugin level through runInBackground on iOS and cordova.getThreadPool on android iirc.

from cordova-plugin-scrypt.

homakov avatar homakov commented on July 26, 2024

@ggozad I've figured out I don't need to runInBackground because the speed is the same.

Side question: have you looked into integrating other cordova platforms such as UWP and osx? Or is it a lot of extra coding?

from cordova-plugin-scrypt.

ggozad avatar ggozad commented on July 26, 2024

Hey @homakov. I haven't looked at osx or windows. I would imagine osx must be very straightforward, probably the iOS thing will do just fine. Windows on the other hand might be a world of pain.

from cordova-plugin-scrypt.

ggozad avatar ggozad commented on July 26, 2024

With regards to background it's worthwhile if you wanna do it and I would be happy to accept it. It would not of course change the speed, but it would free up the main thread for UI. Let me know if I can close this, we can take background seperately.

from cordova-plugin-scrypt.

homakov avatar homakov commented on July 26, 2024

Got it.
So, in the end big p is not so slow if compiled in --release mode and compiler optimization to Fastest. Closing it.

from cordova-plugin-scrypt.

Related Issues (3)

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.