Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: fa83cf53f871966898862ed6dc7c08e51519de64
      
https://github.com/WebKit/WebKit/commit/fa83cf53f871966898862ed6dc7c08e51519de64
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-04-18 (Sat, 18 Apr 2026)

  Changed paths:
    A JSTests/microbenchmarks/rope-single-char-endsWith.js
    A JSTests/microbenchmarks/rope-single-char-startsWith.js
    A JSTests/stress/string-starts-ends-with-rope-single-char.js
    M Source/JavaScriptCore/dfg/DFGOperations.cpp
    M Source/JavaScriptCore/runtime/JSString.h
    M Source/JavaScriptCore/runtime/JSStringInlines.h
    M Source/JavaScriptCore/runtime/StringPrototype.cpp

  Log Message:
  -----------
  [JSC] Avoid rope resolution for single-char `startsWith` / `endsWith`
https://bugs.webkit.org/show_bug.cgi?id=311891

Reviewed by Yusuke Suzuki.

When the search string is a single character and the receiver is a rope
longer than minLengthForRopeWalk, we only need one character from the
rope to answer startsWith / endsWith. Resolving the whole rope just to
read that one character is wasteful.

This patch adds JSString::tryGetCharAt(), a sibling of tryFindOneChar()
that walks at most one level of fibers and returns the character at the
requested index.

                                     TipOfTree                  Patched

rope-single-char-startsWith       14.0873+-1.8901     ^      1.5065+-0.0736     
   ^ definitely 9.3512x faster
rope-single-char-endsWith         13.5408+-0.2436     ^      1.5653+-0.0427     
   ^ definitely 8.6505x faster

Tests: JSTests/microbenchmarks/rope-single-char-endsWith.js
       JSTests/microbenchmarks/rope-single-char-startsWith.js
       JSTests/stress/string-starts-ends-with-rope-single-char.js

* JSTests/microbenchmarks/rope-single-char-endsWith.js: Added.
(testHit):
(testMiss):
* JSTests/microbenchmarks/rope-single-char-startsWith.js: Added.
(testHit):
(testMiss):
* JSTests/stress/string-starts-ends-with-rope-single-char.js: Added.
(shouldBe):
(throw.new.Error.sw):
(throw.new.Error.ew):
(throw.new.Error):
(shouldBe.swp):
(shouldBe.ewp):
(shouldBe.sw):
(shouldBe.ew):
* Source/JavaScriptCore/dfg/DFGOperations.cpp:
(JSC::DFG::JSC_DEFINE_JIT_OPERATION):
* Source/JavaScriptCore/runtime/JSString.h:
* Source/JavaScriptCore/runtime/JSStringInlines.h:
(JSC::JSString::tryGetCharAt const):
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

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



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

Reply via email to