[Webkit-unassigned] [Bug 240290] New: [JSC] Add two fast paths for Array.from

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue May 10 15:14:30 PDT 2022


https://bugs.webkit.org/show_bug.cgi?id=240290

            Bug ID: 240290
           Summary: [JSC] Add two fast paths for Array.from
           Product: WebKit
           Version: WebKit Nightly Build
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: JavaScriptCore
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: jarred at jarredsumner.com

Created attachment 459136

  --> https://bugs.webkit.org/attachment.cgi?id=459136&action=review

microbenchmark.js

Two fast paths for Array.from:

1. Similar to https://bugs.webkit.org/show_bug.cgi?id=239936, a fast path for Array.from (ArrayConstructor) given an array of Int32 or double that uses something like:
- @appendMemcpy
- Array.prototype.slice

If the array iterator protocol is unmodified. 

2. Given input like this: Array.from({length: number}), it could skip the loop that sets undefined on each element

A microbenchmark shows that for new Array(length) is about 32x faster than Array.from({length})


❯ jsc /tmp/a.js
new Array(2097152): 79.586ms
Array.from({length: 2097152}): 2,595.839ms

You can see this pattern is fairly common on GitHub: https://sourcegraph.com/search?q=context:global+Array.from%28%7Blength&patternType=literal


Also:

When there is `items.@@iterator`, is it intentional that the array isn't initialized with a length? Could it read the length if defined? 
> var result = this !== @Array && @isConstructor(this) ? new this() : [];


https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/builtins/ArrayConstructor.js#L60

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20220510/f612af17/attachment-0001.htm>


More information about the webkit-unassigned mailing list