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 require() of v1 #189
Comments
What kind of time are we talking about here? msecs? secs?
That's for node.js though, not the browser, right? How does that affect window load time in your clients? I would expect the entropy of a node.js server to have been established by the time it's ready to start handling requests.
I think you mean rng.js, as that's where this issue should be addressed. I'm open to fixing this, but adding/converting to an async api is a non-trivial change. I'd like to make sure it's actually solving a real problem. That your problem goes away when you switch to v4() has me suspicious... 😕 (I could be way off base on all of this, btw... I won't pretend to know with certainty what |
Thanks for the quick response @broofa. In terms of slowdown, we're talking the difference between 20ms and 300ms. Electron is a framework for building desktop apps with web technologies. Each window is a separate process, including a separate instance of NodeJS. Therefore each window's From the v1 source;
Each time Compared to v4
Where the only thing happening at This is where the performance difference is coming from. The difference in time in the process' lifecycle when |
We're seeing this behavior as well albeit with a much higher penalty (around 1 second for the initial call) We're using webpack and typescript and import the v4 version using an import statement, this causes the v1 version to get loaded as well. It seems like the initial call to For now we've worked around the issue by creating our own wrapper around uuid that sources entropy using window.crypto instead of the Node.JS crypto module and the initial load time is now trivial. I threw up my workaround in a gist if you're interested @chgibb. |
Update: there's already an issue tracking this in electron, see electron/electron#2073 |
Thanks @niik !! |
Using
require("uuid/v1")
under Electron, I've noticed anywhere from 2x to 4x increase in window load time. I've tracked this to the unwrapped call torng()
which in turn synchronously callscrypto.randomBytes()
. From the NodeJS docs:The crypto.randomBytes() method will block until there is sufficient entropy. This should normally never take longer than a few milliseconds. The only time when generating the random bytes may conceivably block for a longer period of time is right after boot, when the whole system is still low on entropy.
This is unfortunately the behvaviour I'm seeing. The loading of the entire window is being held up by the call to
crypto.randomBytes
. Changing my use ofuuid/v1
touuid/v4
fixes the problem.If there is sufficient interest in modifying
uuid/v1
to use the asynchronous version ofcrypto.randomBytes
or otherwise wrap the synchronous version so it is not called on require time I would be happy to open a PR.The text was updated successfully, but these errors were encountered: