perf(ext/crypto): batch randomUUID generation#35953
Merged
Merged
Conversation
nathanwhit
marked this pull request as ready for review
July 10, 2026 20:47
bartlomieju
pushed a commit
that referenced
this pull request
Jul 15, 2026
## Summary
- generate 128 formatted UUIDs per native refill and return them as one
packed one-byte V8 string
- serve normal `crypto.randomUUID()` calls from JavaScript slices,
reducing native transitions to one per batch
- retain the native per-call implementation for `--seed` so mixed
`randomUUID()` and `getRandomValues()` calls preserve deterministic RNG
ordering
- honor `node:crypto.randomUUID({ disableEntropyCache: true })` with an
uncached generation path
## Performance
Focused `release-lite` benchmark using the website benchmark helper:
| Runtime | ops/sec |
| --- | ---: |
| Deno website baseline | 9.50M |
| Deno patched | 16.60M-17.12M |
| Node 26.3.0, same local harness | 16.97M |
The implementation uses the same 128-UUID batch size as Node, but
formats the whole batch in Rust into one packed string. The JavaScript
hot path only slices the next 36-byte UUID, avoiding both a native call
and per-byte formatting for 127 of every 128 calls.
## Validation
- `cargo check -p deno_crypto`
- `cargo test -p deno_crypto test_fast_uuid_v4_correctness`
- `cargo fmt --check`
- `./tools/lint.js ext/crypto/00_crypto.js ext/crypto/crypto.rs
ext/crypto/lib.rs ext/node/polyfills/internal/crypto/random.ts
tests/unit_node/crypto/crypto_misc_test.ts`
- `./target/release-lite/deno test --config tests/config/deno.json
tests/unit_node/crypto/crypto_misc_test.ts`
- `PYENV_VERSION=3.11.8 ./tests/wpt/wpt.ts run
--binary=./target/release-lite/deno -- WebCryptoAPI/randomUUID`
- generated 1,000 UUIDs across multiple refills and checked UUID v4
shape and uniqueness
- repeated mixed `randomUUID()` / `getRandomValues()` calls under
`--seed=100` in separate processes and confirmed identical output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
Summary
crypto.randomUUID()calls from JavaScript slices, reducing native transitions to one per batch--seedso mixedrandomUUID()andgetRandomValues()calls preserve deterministic RNG orderingnode:crypto.randomUUID({ disableEntropyCache: true })with an uncached generation pathPerformance
Focused
release-litebenchmark using the website benchmark helper:The implementation uses the same 128-UUID batch size as Node, but formats the whole batch in Rust into one packed string. The JavaScript hot path only slices the next 36-byte UUID, avoiding both a native call and per-byte formatting for 127 of every 128 calls.
Validation
cargo check -p deno_cryptocargo test -p deno_crypto test_fast_uuid_v4_correctnesscargo fmt --check./tools/lint.js ext/crypto/00_crypto.js ext/crypto/crypto.rs ext/crypto/lib.rs ext/node/polyfills/internal/crypto/random.ts tests/unit_node/crypto/crypto_misc_test.ts./target/release-lite/deno test --config tests/config/deno.json tests/unit_node/crypto/crypto_misc_test.tsPYENV_VERSION=3.11.8 ./tests/wpt/wpt.ts run --binary=./target/release-lite/deno -- WebCryptoAPI/randomUUIDrandomUUID()/getRandomValues()calls under--seed=100in separate processes and confirmed identical output