Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 082efc20347d20d555bc7c5fb2c349e791495859
      
https://github.com/WebKit/WebKit/commit/082efc20347d20d555bc7c5fb2c349e791495859
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-07-01 (Wed, 01 Jul 2026)

  Changed paths:
    M JSTests/microbenchmarks/string-trim-end-unicode-whitespace.js
    M JSTests/microbenchmarks/string-trim-end.js
    A JSTests/microbenchmarks/string-trim-no-whitespace.js
    M JSTests/microbenchmarks/string-trim-start-unicode-whitespace.js
    M JSTests/microbenchmarks/string-trim-start.js
    M JSTests/microbenchmarks/string-trim-unicode-whitespace.js
    A JSTests/microbenchmarks/string-trim-whitespace.js
    M JSTests/microbenchmarks/string-trim.js
    A JSTests/stress/string-trim-intrinsic.js
    M Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h
    M Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp
    M Source/JavaScriptCore/dfg/DFGClobberize.h
    M Source/JavaScriptCore/dfg/DFGCloneHelper.h
    M Source/JavaScriptCore/dfg/DFGDoesGC.cpp
    M Source/JavaScriptCore/dfg/DFGFixupPhase.cpp
    M Source/JavaScriptCore/dfg/DFGNode.h
    M Source/JavaScriptCore/dfg/DFGNodeType.h
    M Source/JavaScriptCore/dfg/DFGOperations.cpp
    M Source/JavaScriptCore/dfg/DFGOperations.h
    M Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp
    M Source/JavaScriptCore/dfg/DFGSafeToExecute.h
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp
    M Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp
    M Source/JavaScriptCore/ftl/FTLCapabilities.cpp
    M Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp
    M Source/JavaScriptCore/runtime/Intrinsic.h
    M Source/JavaScriptCore/runtime/StringPrototype.cpp
    M Source/JavaScriptCore/runtime/StringPrototypeInlines.h

  Log Message:
  -----------
  [JSC] Handle `String#trim`, `String#trimStart` and `String#trimEnd` in DFG / 
FTL
https://bugs.webkit.org/show_bug.cgi?id=318185

Reviewed by Yusuke Suzuki.

This patch adds StringPrototypeTrimIntrinsic, 
StringPrototypeTrimStartIntrinsic, and
StringPrototypeTrimEndIntrinsic, and handles them in DFG and FTL via a new 
StringTrim
node. For now, the DFG / FTL implementation simply speculates StringUse on the 
receiver
and calls a JIT operation. We can optimize this further in future patches, e.g. 
by
emitting the whitespace scan as inline JIT code and allocating the substring 
rope inline.

This patch also updates the existing string-trim* microbenchmarks so that they 
consume
the trim results and rotate the input strings: since StringTrim is a pure node, 
the
previous result-discarding loop bodies were eliminated by DCE / LICM and no 
longer
measured trim itself.

                                                 ToT                     Patched

string-trim-start-unicode-whitespace       45.2619+-0.9021     ^     
39.7963+-0.8249        ^ definitely 1.1373x faster
string-trim-end-unicode-whitespace         47.1853+-1.1061     ^     
42.3641+-1.0792        ^ definitely 1.1138x faster
string-trim-whitespace                    112.0596+-1.8629     ^     
49.2140+-0.8692        ^ definitely 2.2770x faster
string-trim-no-whitespace                  41.4868+-0.6042     ^     
17.3533+-0.3159        ^ definitely 2.3907x faster
string-trim                                82.4187+-0.9117     ^     
40.3063+-1.9017        ^ definitely 2.0448x faster
string-trim-unicode-whitespace             81.8615+-2.1368     ^     
75.6034+-1.9905        ^ definitely 1.0828x faster
string-trim-end                            76.7737+-1.0939     ^     
36.0213+-0.4923        ^ definitely 2.1313x faster
string-trim-start                          76.8228+-0.7388     ^     
32.7010+-1.0362        ^ definitely 2.3492x faster

Tests: JSTests/microbenchmarks/string-trim-no-whitespace.js
       JSTests/microbenchmarks/string-trim-whitespace.js
       JSTests/stress/string-trim-intrinsic.js

* JSTests/microbenchmarks/string-trim-end-unicode-whitespace.js:
* JSTests/microbenchmarks/string-trim-end.js:
* JSTests/microbenchmarks/string-trim-no-whitespace.js: Added.
(test):
* JSTests/microbenchmarks/string-trim-start-unicode-whitespace.js:
* JSTests/microbenchmarks/string-trim-start.js:
* JSTests/microbenchmarks/string-trim-unicode-whitespace.js:
* JSTests/microbenchmarks/string-trim-whitespace.js: Added.
(test):
* JSTests/microbenchmarks/string-trim.js:
* JSTests/stress/string-trim-intrinsic.js: Added.
(shouldBe):
(testTrim):
(testTrimStart):
(testTrimEnd):
(shouldBe.String.prototype.trim.call.toString):
(testTrimPolymorphic):
* Source/JavaScriptCore/dfg/DFGAbstractInterpreterInlines.h:
(JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects):
* Source/JavaScriptCore/dfg/DFGByteCodeParser.cpp:
(JSC::DFG::ByteCodeParser::handleIntrinsicCall):
* Source/JavaScriptCore/dfg/DFGClobberize.h:
(JSC::DFG::clobberize):
* Source/JavaScriptCore/dfg/DFGCloneHelper.h:
* Source/JavaScriptCore/dfg/DFGDoesGC.cpp:
(JSC::DFG::doesGC):
* Source/JavaScriptCore/dfg/DFGFixupPhase.cpp:
(JSC::DFG::FixupPhase::fixupNode):
* Source/JavaScriptCore/dfg/DFGNode.h:
(JSC::DFG::Node::hasIntrinsic):
* Source/JavaScriptCore/dfg/DFGNodeType.h:
* Source/JavaScriptCore/dfg/DFGOperations.cpp:
(JSC::DFG::stringTrimImpl):
(JSC::DFG::JSC_DEFINE_JIT_OPERATION):
* Source/JavaScriptCore/dfg/DFGOperations.h:
* Source/JavaScriptCore/dfg/DFGPredictionPropagationPhase.cpp:
* Source/JavaScriptCore/dfg/DFGSafeToExecute.h:
(JSC::DFG::safeToExecute):
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT.cpp:
(JSC::DFG::SpeculativeJIT::compileStringTrim):
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT.h:
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT32_64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* Source/JavaScriptCore/dfg/DFGSpeculativeJIT64.cpp:
(JSC::DFG::SpeculativeJIT::compile):
* Source/JavaScriptCore/ftl/FTLCapabilities.cpp:
(JSC::FTL::canCompile):
* Source/JavaScriptCore/ftl/FTLLowerDFGToB3.cpp:
(JSC::FTL::DFG::LowerDFGToB3::compileNode):
(JSC::FTL::DFG::LowerDFGToB3::compileCompareStrictEq):
* Source/JavaScriptCore/runtime/Intrinsic.h:
* Source/JavaScriptCore/runtime/StringPrototype.cpp:
(JSC::StringPrototype::finishCreation):
(JSC::trimString):
* Source/JavaScriptCore/runtime/StringPrototypeInlines.h:
(JSC::extractTrimOffsets):

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



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

Reply via email to