Now published as @root/uuid
- Node version: https://github.com/therootcompany/uuid.js/blob/main/uuid.js
- Browser version: https://github.com/therootcompany/uuid.js/blob/main/browser.js
This is started out as a curiosity, pasted as a gist but now, years later, I've come back to it because there are too many of these uuid modules out there and they're too complicated.
This, however, is easy to read and understand (for me, at least). Even its tests are dependncy and build-step free.
Everybody knows about node-uuid and that it's pretty fast, right?
And everybody knows about 140byte-uuid and that it's insanely small, but really slow, right?
Well, while I was looking at all that math in node-uuid, I wondered to myself: Is that really all that more efficient than just accessing strings? (BTW, I was totally looking at the wrong function)
So I set out on a mission to make 'if' blocks and strings faster than bitwise operations, and I did! Over 2x faster! (generally in the range of 550,000/s instead of 250,000/s)
Note that the huge time saver here is actually pooling crypto.randomBytes()
ahead of time.
If we were to implement the same thing in node-uuid
we might see an even bigger increase.
Copyright 2021 The Root Group, LLC
Copyright 2015-2021 AJ ONeal
This Source Code Form is subject to the terms of the Mozilla
Public License, v. 2.0. If a copy of the MPL was not distributed
with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
So, will this be published to NPM? Or is it already and I just suck at searching?