[webkit-changes] [WebKit/WebKit] 8b7e7e: [JSC] Improve String#split for uglify-js-wtb

Yusuke Suzuki noreply at github.com
Tue Feb 7 00:14:46 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 8b7e7ed621bf5db6b4a46fb191f20d6d03a36589
      https://github.com/WebKit/WebKit/commit/8b7e7ed621bf5db6b4a46fb191f20d6d03a36589
  Author: Yusuke Suzuki <ysuzuki at apple.com>
  Date:   2023-02-07 (Tue, 07 Feb 2023)

  Changed paths:
    A JSTests/microbenchmarks/string-split-space.js
    A JSTests/microbenchmarks/string-split.js
    M Source/JavaScriptCore/runtime/RegExpPrototype.cpp
    M Source/JavaScriptCore/yarr/YarrJIT.cpp

  Log Message:
  -----------
  [JSC] Improve String#split for uglify-js-wtb
https://bugs.webkit.org/show_bug.cgi?id=251823
rdar://105104781

Reviewed by Michael Saboff.

This patch improves JetStream2/uglify-js-wtb by 1% with String#split optimizations.

1. We should just use ArrayWithContigous array for result of String#split, and let's say `1` capacity at least.
   At that point, we will always return an array with at least one capacity. So, let's avoid structure transition,
   and butterfly reallocation.
2. We should search for BoyerMoore lookahead character patterns with Greedy one-character pattern. For example,
   /\r?\n/ is very frequently used. We should search for [\r\n] character to start matching in this case.
   However, if we have /\r?\n/ pattern,
       1. first character can be [\r\n]
       2. second character can be null, or [\n]
   So, this confuses fixed-sized BoyerMoore lookahead generation. So, when we encounter greedy one-character pattern, we cut
   the BM prefix length at this point. So, in the above case, we only consider about first character [\r\n] case.
   This is still beneficial since previously we give up completely when we encounter greedy fixed-sized one-character pattern.

                                   ToT                     Patched

    string-split-space      130.3261+-0.7798     ^    125.6028+-0.4402        ^ definitely 1.0376x faster
    string-split            206.8225+-1.1932     ^    128.5716+-0.7137        ^ definitely 1.6086x faster

* JSTests/microbenchmarks/string-split-space.js: Added.
(split):
* JSTests/microbenchmarks/string-split.js: Added.
(split):
* Source/JavaScriptCore/runtime/RegExpPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/yarr/YarrJIT.cpp:

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




More information about the webkit-changes mailing list