[webkit-changes] [WebKit/WebKit] 213595: [JSC] Add fast path for `array.concat()`

SUZUKI Sosuke noreply at github.com
Sun Sep 22 23:06:14 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 21359545c81d7899938c4b2e0e15c327586dcb89
      https://github.com/WebKit/WebKit/commit/21359545c81d7899938c4b2e0e15c327586dcb89
  Author: Sosuke Suzuki <aosukeke at gmail.com>
  Date:   2024-09-22 (Sun, 22 Sep 2024)

  Changed paths:
    A JSTests/microbenchmarks/array-prototype-concat-copy-double-and-int32.js
    A JSTests/microbenchmarks/array-prototype-concat-copy-double.js
    A JSTests/microbenchmarks/array-prototype-concat-copy-int32.js
    A JSTests/microbenchmarks/array-prototype-concat-copy-obj.js
    A JSTests/stress/array-prototype-concat-copy-empty.js
    M Source/JavaScriptCore/builtins/ArrayConstructor.js
    M Source/JavaScriptCore/builtins/ArrayPrototype.js
    M Source/JavaScriptCore/builtins/BuiltinNames.h
    M Source/JavaScriptCore/bytecode/LinkTimeConstant.h
    M Source/JavaScriptCore/runtime/ArrayPrototype.cpp
    M Source/JavaScriptCore/runtime/ArrayPrototype.h
    M Source/JavaScriptCore/runtime/JSArray.cpp
    M Source/JavaScriptCore/runtime/JSArray.h
    M Source/JavaScriptCore/runtime/JSGlobalObject.cpp

  Log Message:
  -----------
  [JSC] Add fast path for `array.concat()`
https://bugs.webkit.org/show_bug.cgi?id=279862

Reviewed by Yusuke Suzuki.

This patch adds fast path for `array.concat()` using same way as `Array.from(array)`.

`Array.from()` fills any empty slots in the array with `undefined`. On the other hand,
`Array.prototype.concat` preserves empty slots. So, this patch tweaks `tryCloneArrayFromFast`.

According to microbench it is 1.5~6x faster.

                                                 TipOfTree                  Patched

array-prototype-concat-copy-obj                 1.5540+-0.0570     ^      0.9991+-0.0218        ^ definitely 1.5554x faster
array-prototype-concat-copy-double-and-int32
                                                1.9665+-0.4020     ^      1.1984+-0.0770        ^ definitely 1.6409x faster
array-prototype-concat-copy-double              1.5371+-0.1052     ^      0.9618+-0.0419        ^ definitely 1.5982x faster
array-prototype-concat-copy-int32               1.5674+-0.1159     ^      0.9719+-0.0541        ^ definitely 1.6127x faster

<geometric>                                     1.6457+-0.1324     ^      1.0283+-0.0293        ^ definitely 1.6004x faster

Exist benchmarks of Arrray.prototype.concat show no performance regressions.

* JSTests/microbenchmarks/array-prototype-concat-copy-double-and-int32.js: Added.
(shouldBe):
(test):
* JSTests/microbenchmarks/array-prototype-concat-copy-double.js: Added.
(shouldBe):
(test):
* JSTests/microbenchmarks/array-prototype-concat-copy-int32.js: Added.
(shouldBe):
(test):
* JSTests/microbenchmarks/array-prototype-concat-copy-obj.js: Added.
(shouldBe):
(test):
* JSTests/stress/array-prototype-concat-copy-empty.js: Added.
(shouldBe):
(throw.new.Error):
* Source/JavaScriptCore/builtins/ArrayConstructor.js:
* Source/JavaScriptCore/builtins/ArrayPrototype.js:
(concat):
* Source/JavaScriptCore/builtins/BuiltinNames.h:
* Source/JavaScriptCore/bytecode/LinkTimeConstant.h:
* Source/JavaScriptCore/runtime/ArrayPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/ArrayPrototype.h:
* Source/JavaScriptCore/runtime/JSArray.cpp:
(JSC::tryCloneArrayFromFast):
* Source/JavaScriptCore/runtime/JSArray.h:
* Source/JavaScriptCore/runtime/JSGlobalObject.cpp:
(JSC::JSGlobalObject::init):
* Source/JavaScriptCore/runtime/JSIteratorPrototype.cpp:
(JSC::JSC_DEFINE_HOST_FUNCTION):

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



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


More information about the webkit-changes mailing list