You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
First invoke of module's (crypto) method is extremely slow #2073
I've noticed quite a big lag while adding first record in my application and after doing some tests it turned out that running crypto.randomBytes() for the first time takes incomparably longer than for all the consecutive runs. Here's the test code:
We have observed the same in VS Code (microsoft/vscode#22086) with times of around 1 second in the renderer. Also, we pay the price every time electron starts, whereas node isn't slow on subsequent starts.
Put the below snippet in renderer.js of the quick start sample, keep refreshing the renderer and see it always being slow, not (re-)using any sort of OS-level entropy
We've also observed the same behavior with initial load times of over a second on Windows 10. We spotted it using the uuid module (see uuidjs/uuid#189 (comment))
We've worked around it for now by using window.crypto as our source of entropy for uuid but since we could end up having one of our other dependencies source through the NodeJS crypto module it'd be real nice if we could solve this in electron proper.
I was able to work around the issue by initializing the crypto module on application start using the callback of the crypto.randomBytes method. This way, the initial load is performed in the background, without blocking the UI thread. A later synchronous call can then be made without delay.
setTimeout(()=>{// asynchronously initialize the crypto librarycrypto.randomBytes(1,()=>{// done});},1000);
Still, a proper fix would be nice, esp. as the bug also applies to the RSA methods (crypto.privateDecrypt etc.).
Activity
zcbenz commentedon Jun 29, 2015
Which OS are you using?
jrieken commentedon Mar 7, 2017
We have observed the same in VS Code (microsoft/vscode#22086) with times of around 1 second in the renderer. Also, we pay the price every time electron starts, whereas node isn't slow on subsequent starts.
Put the below snippet in
renderer.jsof the quick start sample, keep refreshing the renderer and see it always being slow, not (re-)using any sort of OS-level entropyniik commentedon Apr 27, 2017
We've also observed the same behavior with initial load times of over a second on Windows 10. We spotted it using the
uuidmodule (see uuidjs/uuid#189 (comment))We've worked around it for now by using window.crypto as our source of entropy for
uuidbut since we could end up having one of our other dependencies source through the NodeJS crypto module it'd be real nice if we could solve this in electron proper.chgibb commentedon Apr 27, 2017
As a temporary work around, we've switched to using node-uuid's
v4module as it does not invokecrypto.randomBytesat require time.Doccrazy commentedon Nov 18, 2017
I was able to work around the issue by initializing the crypto module on application start using the callback of the
crypto.randomBytesmethod. This way, the initial load is performed in the background, without blocking the UI thread. A later synchronous call can then be made without delay.Still, a proper fix would be nice, esp. as the bug also applies to the RSA methods (
crypto.privateDecryptetc.).nornagon commentedon Apr 30, 2019
I can't reproduce this on Electron 3, 4 or 5. Here's the fiddle I'm using: https://gist.github.com/9b2e03eb35953a8e47342c7d9a9b94be
Is there something I'm missing? I tried this on Windows and macOS, and didn't observe any timings above ~20ms.
zcbenz commentedon Apr 30, 2019
Probably silently fixed in upstream.
nornagon commentedon May 1, 2019
Closing this for now, reopen if you find a way to reproduce it :)
PriyankuBiswas-EH commentedon Oct 3, 2024
The issue is resolved in v32.1.2 as far i see. In version 26 it was very slow.