Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 0f79baf7bc085f19e03dcbce2800870afb57eeb7
      
https://github.com/WebKit/WebKit/commit/0f79baf7bc085f19e03dcbce2800870afb57eeb7
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-07-25 (Sat, 25 Jul 2026)

  Changed paths:
    M Source/JavaScriptCore/yarr/YarrJIT.cpp

  Log Message:
  -----------
  [YARR] `tryReadUnicodeChar` should read the first code unit before testing 
whether a second one is needed
https://bugs.webkit.org/show_bug.cgi?id=320088

Reviewed by Yusuke Suzuki.

tryReadUnicodeCharImpl loads 32 bits up front so that it can detect a
surrogate pair, and therefore checks that both code units are in bounds before
loading anything.

Surrogate pairs are rare compared to BMP code points, though, and deciding
whether a code unit is a BMP code point on its own does not need 32 bits. Load
the first code unit alone and test its top five bits: U+D800-U+DFFF are exactly
the code units whose top five bits are 0b11011. If it is not a surrogate, it is
the code point, so jump to done right there. Only if it is a surrogate do we
check the bounds, load 32 bits, and either decode a proper surrogate pair or
fall into the slow cases.

Keeping the bit 15 test from 317749@main as the fast-path branch would take
fewer instructions, but that branch depends on the character being read and
mispredicts badly once the subject mixes code units below and above U+8000.
The surrogate test costs one more instruction but only changes direction when
a surrogate actually appears.

                                            Baseline           Patched

regexp-unicode-bmp-hangul-and-fullwidth 43.9718+-0.9491    34.3181+-2.8952   
definitely 1.2813x faster
regexp-unicode-bmp-above-latin          45.6190+-0.7442    35.8214+-2.6717   
definitely 1.2735x faster
regexp-u-global-es6                     31.8327+-0.2765    30.5326+-0.3346   
definitely 1.0426x faster
regexp-unicode-latin-before-surrogate   55.0738+-1.6395    52.8071+-3.0785   
might be 1.0429x faster
regexp-unicode-surrogate-pairs          45.9197+-1.5007    46.1131+-1.7645   
neutral

* Source/JavaScriptCore/yarr/YarrJIT.cpp:
(JSC::Yarr::tryReadUnicodeCharImpl):

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



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

Reply via email to