-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
slow #3
Comments
True, just tested with With 1024 bits you get key pairs in 500ms-2s. 20-30 seconds def. sucks :D Maybe this can be rewritten more effectively with a buffer bigint abstraction... I'll add a note to the readme. |
Thanks @juliangruber. I'm curious how an emscriptened version of whatever ssh-keygen uses would fare out of the box compared to this handcrafted stuff. |
The functions keypair uses are just copied over from node-forge. Unfortunately node-forge doesn't yet use typedarrays/buffers (digitalbazaar/forge#60) so that could make it faster. Would an emscriptened code used typed arrays? |
@juliangruber yeah afaik emscripten emulates heap allocation/access using typed arrays. This may or may not improve performance though as there may be some inefficiency introduced by compiling to js, but my understanding is that emscripten will use lower level constructs by default, which is how it manages to get great perf out of stuff that wasn't even designed for js. asm.js is supposed to make this even more magic by providing more hints to the js engine about what kinds of optimisations it can safely perform. |
if you manage to do this i'd gladly replace this module's index.js with |
Just a note: using TypedArrays/buffers has no real effect on the speed issue here. Generating RSA keys is slow because it involves looking for large prime numbers (the larger the bit size, the larger the numbers). The process involves incrementing a counter and then checking the result to see if it's a probable prime or not via (very slow) modular exponentiation. That's where the real bottleneck is. There are some new papers on faster prime generation that have come out recently that I've been looking into in order to speed up the implementation in forge. However, there's no ETA on such an upgrade (or how much it would improve things) yet. If you're concerned about blocking the main thread, forge has two options for avoiding this; you can use the step-by-step key generation mechanism in a setTimeout/setImmediate loop or you can use the built-in Web Workers approach that also includes an automatic # of cores detection run to try to optimize the # of Web Workers used for key generation. Anyway -- my main note here is that the use of TypedArrays (or not) is unlikely to have that great of a performance impact on large prime number generation in JavaScript. |
not sure if there is anything that can be done about this but generating keys is damn slow:
Output of multiple runs on Macbook, 3GHz Intel Core i7:
It seems to be more slow on the first run, I guess that's v8 getting it's optimisation on?
If this isn't isolated to me, it might be worthwhile mentioning performance in the readme, and recommend this be run in a child process or something to keep the blocking out of the main thread.
The text was updated successfully, but these errors were encountered: