Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 046a5a8d15c6af2ef00ea4b591316eebe6540561
      
https://github.com/WebKit/WebKit/commit/046a5a8d15c6af2ef00ea4b591316eebe6540561
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-10-02 (Fri, 02 Oct 2026)

  Changed paths:
    A JSTests/microbenchmarks/string-index-of-one-char-long.js
    A JSTests/microbenchmarks/string-index-of-one-char-short.js
    A JSTests/stress/string-index-of-one-char-boundary-lengths.js
    M Source/WTF/wtf/text/StringCommon.cpp
    M Source/WTF/wtf/text/StringCommon.h
    M Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp

  Log Message:
  -----------
  [WTF] `find8` should not scan the first 16 bytes one by one
https://bugs.webkit.org/show_bug.cgi?id=325953

Reviewed by Yusuke Suzuki.

find8() compares the first 16 bytes one by one, and then calls memchr. This
is slow when the character is not in the first few bytes, as in
`"content-type: text/plain".indexOf("/")`. 318252@main fixed the same problem
in find16() and find32().

This patch compares the first 16 bytes at once with SIMD. If the character is
not there, it calls an out-of-line function, which searches the first 64
bytes with findImpl() and the rest with memchr as before. Strings shorter
than 16 bytes keep the current loop. The function is out of line because
`url.replace(/^https?:\/\//, "")` got 4% slower when find8() had the whole
search inline.

                                                   Baseline                  
Patched

string-prototype-includes-with-index-with-one-char
                                               51.7997+-0.7423     ^     
39.3782+-0.8978        ^ definitely 1.3154x faster
string-index-of-one-char-short                 15.6529+-0.1568     ^     
12.3278+-0.1699        ^ definitely 1.2697x faster
uint8-array-index-of-small                      0.3386+-0.0248     ^      
0.2830+-0.0124        ^ definitely 1.1965x faster
string-split-non-atom-subject                  34.3391+-0.3980     ^     
33.2267+-0.3067        ^ definitely 1.0335x faster
string-prototype-includes-with-one-char        31.7998+-0.4603     ^     
24.1540+-0.4486        ^ definitely 1.3165x faster
string-index-of-one-char-long                  27.3555+-0.3030     ^     
21.5047+-0.6449        ^ definitely 1.2721x faster

Tests: JSTests/microbenchmarks/string-index-of-one-char-long.js
       JSTests/microbenchmarks/string-index-of-one-char-short.js
       JSTests/stress/string-index-of-one-char-boundary-lengths.js
       Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp

* JSTests/microbenchmarks/string-index-of-one-char-long.js: Added.
(indexOfNewline):
(includesTab):
* JSTests/microbenchmarks/string-index-of-one-char-short.js: Added.
(indexOfColon):
(includesSlash):
* JSTests/stress/string-index-of-one-char-boundary-lengths.js: Added.
(shouldBe):
(flatten):
(substringSharingBuffer):
* Source/WTF/wtf/text/StringCommon.cpp:
(WTF::find8VectorizedImpl):
* Source/WTF/wtf/text/StringCommon.h:
(WTF::find8):
* Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp:
(TestWebKitAPI::testFindBoundaryLengths):
(TestWebKitAPI::TEST(WTF_StringCommon, Find8BoundaryLengths)):

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



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

Reply via email to