Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 546d47afe6bf2406ad983b5c35e074b85d1643e1
      
https://github.com/WebKit/WebKit/commit/546d47afe6bf2406ad983b5c35e074b85d1643e1
  Author: Sosuke Suzuki <[email protected]>
  Date:   2026-01-08 (Thu, 08 Jan 2026)

  Changed paths:
    A JSTests/microbenchmarks/array-prototype-flat-depth-1-double.js
    A JSTests/microbenchmarks/array-prototype-flat-depth-1-int32.js
    A JSTests/microbenchmarks/array-prototype-flat-depth-1-mixed.js
    A JSTests/microbenchmarks/array-prototype-flat-depth-1-string.js
    A JSTests/microbenchmarks/array-prototype-flat-depth-2.js
    A JSTests/microbenchmarks/array-prototype-flat-depth-3.js
    A JSTests/microbenchmarks/array-prototype-flat-depth-infinity.js
    A JSTests/microbenchmarks/array-prototype-flat-huge-arrays.js
    A JSTests/microbenchmarks/array-prototype-flat-large-nested.js
    A JSTests/microbenchmarks/array-prototype-flat-small-arrays.js
    A JSTests/microbenchmarks/array-prototype-flat-sparse-array.js
    A JSTests/stress/array-prototype-flat-hole.js
    A JSTests/stress/array-prototype-flat-nested-proxy-array.js
    A JSTests/stress/array-prototype-flat-undefined-depth.js
    M Source/JavaScriptCore/builtins/ArrayPrototype.js
    M Source/JavaScriptCore/runtime/ArrayPrototype.cpp
    M Source/JavaScriptCore/runtime/CommonIdentifiers.h
    M Source/JavaScriptCore/runtime/JSArray.cpp
    M Source/JavaScriptCore/runtime/JSArray.h

  Log Message:
  -----------
  [JSC] Implement `Array.prototype.flat` in C++
https://bugs.webkit.org/show_bug.cgi?id=294503

Reviewed by Yusuke Suzuki.

This patch reverts 300343@main to reland 298127@main.

The only change from the original patch is to treat depthNum
as 1 instead of 0 in patterns like `array.flat(undefined)`.

I confirmed that Google Docs works with this patch on my local
Minibrowser build.

-----
(commit message of the original patch)

This patch implements `Array.prototype.flat` in C++.

The new fast path for `Array#flat` first calculates the length
of the resulting array using O(n) `calculateFlattenedLength`,
then directly sets values into the butterfly buffer of the
resulting array using O(n) `fastFlatIntoBuffer`.

                                             TipOfTree                  Patched

array-prototype-flat-depth-1-string      474.3101+-47.2922    ^    
146.0750+-46.3992       ^ definitely 3.2470x faster
array-prototype-flat-depth-1-double      352.0065+-14.2086    ^    
156.4253+-54.2939       ^ definitely 2.2503x faster
array-prototype-flat-large-nested        110.8177+-40.8710    ^     
46.0452+-18.8216       ^ definitely 2.4067x faster
array-prototype-flat-huge-arrays          41.7200+-14.7628    ^     
20.4875+-5.9254        ^ definitely 2.0364x faster
array-prototype-flat-small-arrays         10.1293+-4.8824     ^      
3.8282+-0.4837        ^ definitely 2.6460x faster
array-prototype-flat-depth-infinity      536.4026+-177.3859   ^    
222.0425+-35.8608       ^ definitely 2.4158x faster
array-prototype-flat-depth-2             475.2299+-93.6660    ^    
179.1500+-63.5912       ^ definitely 2.6527x faster
array-prototype-flat-depth-1-int32       453.2263+-184.5728   ^    
154.1721+-56.2397       ^ definitely 2.9397x faster
array-prototype-flat-depth-3             471.8799+-105.4956   ^    
151.9625+-72.1298       ^ definitely 3.1052x faster
array-prototype-flat-sparse-array        172.9858+-58.6417    ?    
219.7328+-64.4558       ? might be 1.2702x slower
array-prototype-flat-depth-1-mixed       465.5951+-149.2841   ^    
177.5621+-96.3248       ^ definitely 2.6222x faster

* JSTests/microbenchmarks/array-prototype-flat-depth-1-double.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-1-int32.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-1-mixed.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-1-string.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-2.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-3.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-depth-infinity.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-huge-arrays.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-large-nested.js: Added.
(shouldBe):
(createLargeNestedArray):
* JSTests/microbenchmarks/array-prototype-flat-small-arrays.js: Added.
(shouldBe):
* JSTests/microbenchmarks/array-prototype-flat-sparse-array.js: Added.
(shouldBe):
* JSTests/stress/array-prototype-flat-hole.js: Added.
(shouldBe):
* JSTests/stress/array-prototype-flat-nested-proxy-array.js: Added.
(shouldBe):
(const.handler.has):
* JSTests/stress/array-prototype-flat-undefined-depth.js: Added.
(shouldBe):
(shouldBeArray):
* Source/JavaScriptCore/builtins/ArrayPrototype.js:
(flat): Deleted.
* Source/JavaScriptCore/runtime/ArrayPrototype.cpp:
(JSC::ArrayPrototype::finishCreation):
(JSC::flatIntoArray):
(JSC::JSC_DEFINE_HOST_FUNCTION):
* Source/JavaScriptCore/runtime/CommonIdentifiers.h:
* Source/JavaScriptCore/runtime/JSArray.cpp:
(JSC::calculateFlattenedLength):
(JSC::fastFlatIntoBuffer):
(JSC::JSArray::fastFlat):
* Source/JavaScriptCore/runtime/JSArray.h:

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



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

Reply via email to