Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fda0e1e0c823a562297b0741b65a93d0f426c877
      
https://github.com/WebKit/WebKit/commit/fda0e1e0c823a562297b0741b65a93d0f426c877
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-01-04 (Sun, 04 Jan 2026)

  Changed paths:
    M Source/WTF/wtf/CMakeLists.txt
    M Source/WTF/wtf/text/StringImpl.cpp
    M Source/WTF/wtf/text/StringImpl.h
    M Source/WTF/wtf/unicode/UTF8Conversion.cpp
    M Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp

  Log Message:
  -----------
  [WTF] Use simdutf for UTF-16 to UTF-8 conversion
https://bugs.webkit.org/show_bug.cgi?id=304916

Reviewed by Yusuke Suzuki.

Add SIMD optimization for UTF-16 to UTF-8 conversion using simdutf library.
This improves performance for non-ASCII strings while remaining neutral for
ASCII strings.

Benchmark results (µs per iteration, lower is better):

Type    Length    Orig(µs)    SIMD(µs)    Speedup
-----   ------    --------    --------    -------
ASCII        5      0.1794      0.1184      1.52x
ASCII       10      0.1350      0.1277      1.06x
ASCII       20      0.1484      0.1454      1.02x
ASCII       50      0.2668      0.1895      1.41x
ASCII      100      0.3188      0.2364      1.35x
ASCII      500      0.6034      0.5830      1.04x
ASCII     1000      1.0247      1.0153      1.01x
JP           5      0.2474      0.1542      1.60x
JP          10      0.3662      0.1847      1.98x
JP          20      0.5966      0.3289      1.81x
JP          50      1.2413      0.5773      2.15x
JP         100      2.5593      0.6513      3.93x
JP         500     11.0678      2.2777      4.86x
JP        1000     22.2872      4.0778      5.46x

Note: ASCII results show some variance in speedup ratios due to fast
execution times, but are effectively neutral. The optimization primarily
benefits non-ASCII text (Japanese, Chinese, emoji, etc.) with 2-5x speedup.

* Source/WTF/wtf/CMakeLists.txt:
Add unicode/UTF8Conversion.cpp to SIMD warning suppression list.
* Source/WTF/wtf/text/StringImpl.cpp:
(WTF::StringImpl::utf8ForCharactersIntoBuffer): Add SIMD fast path.
(WTF::StringImpl::utf8LengthFromUTF16): Added. Calculate exact UTF-8 length
using simdutf.
(WTF::StringImpl::tryConvertUTF16ToUTF8): Added. Try SIMD conversion and
return notFound on failure.
* Source/WTF/wtf/text/StringImpl.h:
(WTF::StringImpl::tryGetUTF8ForCharacters): Use exact buffer sizing with
utf8LengthFromUTF16 and SIMD conversion with tryConvertUTF16ToUTF8.
* Source/WTF/wtf/unicode/UTF8Conversion.cpp:
(WTF::Unicode::convert): Add SIMD fast path for UTF-16 to UTF-8 conversion.
Check buffer size before SIMD conversion to avoid overflow when caller
provides insufficient buffer.

Canonical link: https://commits.webkit.org/305091@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to