deno
2c7aa390 - perf(ext/crypto): batch randomUUID generation (#35953)

Commit
3 days ago
perf(ext/crypto): batch randomUUID generation (#35953) ## 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
Author
Parents
Loading