crypto: improve randomUUID performance#37243
Closed
rangoo94 wants to merge 10 commits intonodejs:masterfrom
Closed
crypto: improve randomUUID performance#37243rangoo94 wants to merge 10 commits intonodejs:masterfrom
rangoo94 wants to merge 10 commits intonodejs:masterfrom
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I very like the idea of including UUIDv4 into node.js core. I think that maximizing its performance could lead to further standardization. The initial version still had the potential for improvements, so I took some effort into it.
Benchmark results
After each step (separate commit), I ran
crypto/randomUUID.jsbenchmark to observe the performance difference.cryptomodule initializationcrypto.randomUUID()callkHexDigits)kHexDigits)sliceon entropy cache)kHexDigits)disableEntropyCacheaccesskHexDigits)00-ffstrings)kHexBytes)kHexByteson firstrandomUUID()callkHexBytes)Entropy cache size
Entropy cache size contributes to the performance, so I prepared a matrix of different sizes on different variants for comparison.
Increasing the entropy cache could be considered for variants 4 and 5, as it will improve ~10% per 1KB of additional cache.
Summary
There are 3 approaches to include the improvements, depending on what is expected:
crypto, even withoutrandomUUID, will take ~2KB of memoryrandomUUIDWhat are your thoughts about that?
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes