Repository navigation
perf(ext/web): use simdutf for base64 encode/decode - #32743
Merged
Merged
Conversation
Replace base64-simd crate with V8's bundled simdutf library for base64 operations. This avoids potential C++ symbol clashes and provides significant performance improvements, especially for decode and write operations (2-3x faster than canary at large sizes). Update v8 crate to 146.7.0 and enable the simdutf feature. Remove base64-simd dependency from ext/web. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use v8::String::new_external_onebyte for base64 output >8KB to avoid copying encoded data into V8's heap. V8 takes ownership of the buffer and frees it on GC, matching Node.js's approach. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use MaybeUninit for stack buffers and Vec::with_capacity for heap buffers to avoid unnecessary zeroing before simdutf overwrites them. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove indirection through forgivingBase64Encode/Decode/etc wrapper functions in 00_infra.js and call ops directly from buffer.mjs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts: # Cargo.lock # Cargo.toml
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves base64 encode/decode performance across deno_web and the Node.js Buffer polyfill by switching from the standalone base64-simd crate to V8’s bundled simdutf base64 implementation (via the v8 crate), and by tightening the Rust↔JS call path for hot operations.
Changes:
- Re-implement
deno_webbase64 ops usingv8::simdutf, including optimized buffer allocation patterns and external V8 string creation for large outputs. - Update the Node
Bufferpolyfill to call the base64 ops directly (instead of going through JS wrapper helpers). - Bump the
v8crate and enable thesimdutffeature; removebase64-simdfromext/webdependencies.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
ext/web/lib.rs |
Switch base64 encode/decode ops to v8::simdutf; add external-string path for large base64 encodes. |
ext/web/Cargo.toml |
Drop base64-simd dependency from deno_web. |
ext/node/polyfills/internal/buffer.mjs |
Route base64 Buffer operations directly to core ops for lower overhead. |
Cargo.toml |
Upgrade v8 crate and enable simdutf feature flag. |
Cargo.lock |
Lockfile updates reflecting v8 bump and dependency graph changes. |
Comments suppressed due to low confidence (1)
ext/node/polyfills/internal/buffer.mjs:978
- The comment says
op_base64_encode_from_bufferusesv8::String::new_external_onebyte, but the Rust implementation only uses external strings when the base64 output exceeds 8KB; smaller outputs still go through the normal one-byte string path (copying into V8). Consider adjusting the comment to reflect the actual threshold/behavior so it doesn’t mislead future performance work.
throw new codes.ERR_BUFFER_OUT_OF_BOUNDS("length");
}
return blitBuffer(asciiToBytes(string), this, offset, length);
…mports Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
nathanwhit
reviewed
Mar 20, 2026
Address review feedback: creating `&mut [u8]` from uninitialized memory (via `from_raw_parts_mut` on `Vec::as_mut_ptr()` or `MaybeUninit`) is undefined behavior even if the consumer only writes. Fix by re-declaring simdutf FFI functions directly with raw pointer signatures (`*mut u8` instead of `&mut [u8]`), so we never need to construct a reference to uninitialized memory. The wrapper `simdutf_base64_encode` now takes `*mut u8` + length, and `simdutf_base64_decode_to_vec` calls the FFI function directly. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
base64-simdcrate with V8's bundled simdutf library (exposed viav8::simdutf) for all base64 encode/decode operationsv8crate to 146.9.0 and enable thesimdutffeaturebase64-simddependency fromext/webv8::String::new_external_onebytefor large base64 encode output (>8KB) to avoid copying into V8's heap, matching Node.js's approachMaybeUninit/Vec::with_capacityto avoid unnecessary zeroing of buffers before simdutf writesbuffer.mjsinstead of going through JS wrapper functionsBenchmark results (50K iterations, ms, lower is better)
vs canary highlights
Towards #24323
Benchmark code
Test plan
cargo clippy -p deno_webpasses./tools/format.jspasses🤖 Generated with Claude Code