From 04a6b2bf606205b4b44bca48eaa6bd70f0a18e9c Mon Sep 17 00:00:00 2001 From: Dan Carney Date: Wed, 5 Nov 2025 15:19:09 +0000 Subject: [PATCH 1/2] deps: V8: cherry-pick 64b36b441179 Original commit message: optimize ascii fast path in WriteUtf8V2 Change-Id: If28168cb4395b953d0ec642ef4fc618ce963dbcd Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/7124103 Reviewed-by: Toon Verwaest Commit-Queue: Erik Corry Reviewed-by: Erik Corry Cr-Commit-Position: refs/heads/main@{#103542} Refs: https://github.com/v8/v8/commit/64b36b44117949fe03df33d077117e7bd6257669 --- common.gypi | 2 +- deps/v8/src/strings/unicode-inl.h | 21 ++++++++++++++++++++- deps/v8/src/strings/unicode.h | 10 ++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/common.gypi b/common.gypi index c5a7dc9cacf8b9..011355970f73b8 100644 --- a/common.gypi +++ b/common.gypi @@ -38,7 +38,7 @@ # Reset this number to 0 on major V8 upgrades. # Increment by one for each non-official patch applied to deps/v8. - 'v8_embedder_string': '-node.41', + 'v8_embedder_string': '-node.43', ##### V8 defaults for Node.js ##### diff --git a/deps/v8/src/strings/unicode-inl.h b/deps/v8/src/strings/unicode-inl.h index 4aa7e8090ca39a..98bd4862e0bcc1 100644 --- a/deps/v8/src/strings/unicode-inl.h +++ b/deps/v8/src/strings/unicode-inl.h @@ -219,6 +219,16 @@ bool Utf8::IsValidCharacter(uchar c) { c != kBadChar); } +template <> +bool Utf8::IsAsciiOneByteString(const uint8_t* buffer, size_t size) { + return simdutf::validate_ascii(reinterpret_cast(buffer), size); +} + +template <> +bool Utf8::IsAsciiOneByteString(const uint16_t* buffer, size_t size) { + return false; +} + template Utf8::EncodingResult Utf8::Encode(v8::base::Vector string, char* buffer, size_t capacity, @@ -234,8 +244,17 @@ Utf8::EncodingResult Utf8::Encode(v8::base::Vector string, const Char* characters = string.begin(); size_t content_capacity = capacity - write_null; CHECK_LE(content_capacity, capacity); - uint16_t last = Utf16::kNoPreviousCharacter; size_t read_index = 0; + if (kSourceIsOneByte) { + size_t writeable = std::min(string.size(), content_capacity); + // Just memcpy when possible. + if (writeable > 0 && Utf8::IsAsciiOneByteString(characters, writeable)) { + memcpy(buffer, characters, writeable); + read_index = writeable; + write_index = writeable; + } + } + uint16_t last = Utf16::kNoPreviousCharacter; for (; read_index < string.size(); read_index++) { Char character = characters[read_index]; diff --git a/deps/v8/src/strings/unicode.h b/deps/v8/src/strings/unicode.h index ef1e717b1ea857..32a0b84a8399b2 100644 --- a/deps/v8/src/strings/unicode.h +++ b/deps/v8/src/strings/unicode.h @@ -212,6 +212,16 @@ class V8_EXPORT_PRIVATE Utf8 { // - valid code point range. static bool ValidateEncoding(const uint8_t* str, size_t length); + template + static bool IsAsciiOneByteString(const Char* buffer, size_t size); + + template <> + inline bool IsAsciiOneByteString(const uint8_t* buffer, size_t size); + + template <> + inline bool IsAsciiOneByteString(const uint16_t* buffer, + size_t size); + // Encode the given characters as Utf8 into the provided output buffer. struct EncodingResult { size_t bytes_written; From 35397451064d608d680191bfa4f0a474f01da76e Mon Sep 17 00:00:00 2001 From: Dhruv Garg Date: Fri, 13 Feb 2026 15:29:05 +0530 Subject: [PATCH 2/2] fix: add missing simdutf.h include in unicode-inl.h --- deps/v8/src/strings/unicode-inl.h | 1 + 1 file changed, 1 insertion(+) diff --git a/deps/v8/src/strings/unicode-inl.h b/deps/v8/src/strings/unicode-inl.h index 98bd4862e0bcc1..b09f65543a7bac 100644 --- a/deps/v8/src/strings/unicode-inl.h +++ b/deps/v8/src/strings/unicode-inl.h @@ -8,6 +8,7 @@ #include "src/strings/unicode.h" // Include the non-inl header before the rest of the headers. +#include "third_party/simdutf/simdutf.h" #include "src/base/logging.h" #include "src/utils/utils.h"