Skip to content

[WTF] Copy short 8-bit spans to 16-bit buffers without a loop - #80001

Merged
webkit-commit-queue merged 1 commit into
WebKit:mainfrom
sosukesuzuki:eng/WTF-Copy-short-8-bit-spans-to-16-bit-buffers-without-a-loop
Nov 25, 2026
Merged

webkit-commit-queue merged 1 commit into
WebKit:mainfrom
sosukesuzuki:eng/WTF-Copy-short-8-bit-spans-to-16-bit-buffers-without-a-loop

Conversation

@sosukesuzuki

@sosukesuzuki sosukesuzuki commented Nov 7, 2026 •

Copy link
Copy Markdown
Member

b5952ce

[WTF] Copy short 8-bit spans to 16-bit buffers without a loop
https://bugs.webkit.org/show_bug.cgi?id=330531

Reviewed by Yusuke Suzuki.

When JSC resolves a 16-bit rope, it widens each 8-bit fiber with
copyElements(uint16_t <- uint8_t). Previously, this function used a loop for every length. On ARM64,
it copied one element at a time when the length was below 64. On x86_64, the compiler vectorized the
loop into several stages, which is slow for a short fiber.

This patch makes the function copy short spans without a loop. It covers the whole span with blocks
anchored at both ends, each of which widens 4 or 8 elements with one load and one store. This is the
widening counterpart of copySmallMemory. Spans longer than 32 elements still use the same loops.

Tests: JSTests/microbenchmarks/rope-resolve-16bit-with-short-8bit-fibers.js
       Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp

* JSTests/microbenchmarks/rope-resolve-16bit-with-short-8bit-fibers.js: Added.
(build):
(check):
* Source/WTF/wtf/text/StringCommon.h:
(WTF::widen4Elements):
(WTF::widen8Elements):
(WTF::copySmallMemoryWidening):
(WTF::copyElements):
* Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp:
(TestWebKitAPI::TEST(WTF_StringCommon, CopyElements8To16)):

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

0ba5b5e

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ⏳ 🛠 ios-sim-cmake ✅ 🛠 mac-cmake-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests
✅ 🧪 webkitperl ⏳ 🧪 ios-cmake-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
skipped 🧪 webkitpy ⏳ 🧪 ios-cmake-wk2-wpt ✅ 🧪 api-mac-cmake-debug ✅ 🧪 jsc-wpe
✅ 🧪 jsc-x86-64 ⏳ 🧪 api-ios-cmake ✅ 🧪 mac-wk2 ✅ 🛠 gtk3-gcc
✅ 🛠 🧪 jsc-debug-arm64 ✅ 🛠 ios-safer-cpp ✅ 🧪 mac-cmake-debug-wk2 ✅ 🛠 gtk
skipped 🧪 services ✅ 🛠 vision skipped 🧪 mac-wk2-stress ✅ 🧪 gtk-wk2
✅ 🛠 🧪 merge ✅ 🛠 vision-sim ✅ 🧪 mac-intel-wk2 ✅ 🧪 api-gtk
✅ 🧪 vision-wk2 ✅ 🛠 mac-safer-cpp ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-site-isolation
✅ 🛠 tv-sim ⏳ 🧪 mac-webdriver
✅ 🛠 watch
✅ 🛠 watch-sim

@sosukesuzuki sosukesuzuki self-assigned this Nov 7, 2026
@sosukesuzuki sosukesuzuki added the merge-queue Applied to send a pull request to merge-queue label Nov 25, 2026
https://bugs.webkit.org/show_bug.cgi?id=330531

Reviewed by Yusuke Suzuki.

When JSC resolves a 16-bit rope, it widens each 8-bit fiber with
copyElements(uint16_t <- uint8_t). Previously, this function used a loop for every length. On ARM64,
it copied one element at a time when the length was below 64. On x86_64, the compiler vectorized the
loop into several stages, which is slow for a short fiber.

This patch makes the function copy short spans without a loop. It covers the whole span with blocks
anchored at both ends, each of which widens 4 or 8 elements with one load and one store. This is the
widening counterpart of copySmallMemory. Spans longer than 32 elements still use the same loops.

Tests: JSTests/microbenchmarks/rope-resolve-16bit-with-short-8bit-fibers.js
       Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp

* JSTests/microbenchmarks/rope-resolve-16bit-with-short-8bit-fibers.js: Added.
(build):
(check):
* Source/WTF/wtf/text/StringCommon.h:
(WTF::widen4Elements):
(WTF::widen8Elements):
(WTF::copySmallMemoryWidening):
(WTF::copyElements):
* Tools/TestWebKitAPI/Tests/WTF/StringCommon.cpp:
(TestWebKitAPI::TEST(WTF_StringCommon, CopyElements8To16)):

Canonical link: https://commits.webkit.org/327768@main
@webkit-commit-queue
webkit-commit-queue force-pushed the eng/WTF-Copy-short-8-bit-spans-to-16-bit-buffers-without-a-loop branch from 0ba5b5e to b5952ce Compare November 25, 2026 15:23
@webkit-commit-queue

Copy link
Copy Markdown
Collaborator

Committed 327768@main (b5952ce): https://commits.webkit.org/327768@main

Reviewed commits have been landed. Closing PR #80001 and removing active labels.

@webkit-commit-queue
webkit-commit-queue merged commit b5952ce into WebKit:main Nov 25, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants