Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: fbc14a1c5a3c08d01ae41a846c9f37b1a7519183
https://github.com/WebKit/WebKit/commit/fbc14a1c5a3c08d01ae41a846c9f37b1a7519183
Author: Ahmad Saleem <[email protected]>
Date: 2026-09-21 (Mon, 21 Sep 2026)
Changed paths:
M Source/WTF/wtf/text/StringCommon.h
M Source/WebCore/page/LocalFrameView.cpp
Log Message:
-----------
Use SIMD to count non-whitespace characters in
LocalFrameView::incrementVisuallyNonEmptyCharacterCountSlowCase()
https://bugs.webkit.org/show_bug.cgi?id=324640
rdar://187887811
Reviewed by Yusuke Suzuki.
nonWhitespaceLength() scanned rendered inline text one character at a
time, decrementing a running length for each ASCII whitespace character.
This runs during initial layout of text-heavy pages, accumulating until
the significant-rendered-text milestone is reached, so it processes
several thousand characters per load.
Replace the scalar loop with the existing bytecount-derived SIMD::count
primitive, which is already portable across NEON/SSE/AVX with a scalar
fallback via simde. A new variadic countMatchedCharacters<chars...>()
overload in StringCommon.h counts characters matching any of a compile-
time set, reusing the variadic SIMD::equal<chars...> mask that already
backs charactersContain(). nonWhitespaceLength() is then just
size - countMatchedCharacters<' ', '\t', '\n', '\f', '\r'>().
The matched set mirrors WTF::isASCIIWhitespace() exactly (the five Infra
"ASCII whitespace" code points; U+000B vertical tab is intentionally not
included), so behavior is unchanged.
incrementVisuallyNonEmptyCharacterCountSlowCase() keeps its NODELETE
annotation since it still runs no destructor, but gets SUPPRESS_NODELETE
on the definition because the NoDeleteChecker cannot see through the
SIMD::count template instantiation and false-positives on it.
A microbenchmark counting non-whitespace over random text (15%
whitespace) measured ~8-18x on 8-bit and ~5-6x on 16-bit input, with
results cross-checked against the scalar implementation for every case.
* Source/WTF/wtf/text/StringCommon.h:
(WTF::countMatchedCharacters):
* Source/WebCore/page/LocalFrameView.cpp:
(WebCore::nonWhitespaceLength):
(WebCore::LocalFrameView::incrementVisuallyNonEmptyCharacterCountSlowCase):
Canonical link: https://commits.webkit.org/321490@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications