<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>240290</bug_id>
          
          <creation_ts>2022-05-10 15:14:30 -0700</creation_ts>
          <short_desc>[JSC] Add NoIndexing miss optimization</short_desc>
          <delta_ts>2022-08-04 10:46:16 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=239936</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Jarred Sumner">jarred</reporter>
          <assigned_to name="Yusuke Suzuki">ysuzuki</assigned_to>
          <cc>saam</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1868023</commentid>
    <comment_count>0</comment_count>
      <attachid>459136</attachid>
    <who name="Jarred Sumner">jarred</who>
    <bug_when>2022-05-10 15:14:30 -0700</bug_when>
    <thetext>Created attachment 459136
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&amp;patternType=literal


Also:

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


https://github.com/WebKit/WebKit/blob/main/Source/JavaScriptCore/builtins/ArrayConstructor.js#L60</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1869824</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2022-05-17 15:15:21 -0700</bug_when>
    <thetext>&lt;rdar://problem/93456330&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1887490</commentid>
    <comment_count>2</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2022-07-28 17:10:30 -0700</bug_when>
    <thetext>Right. Probably this is not so hard.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1887819</commentid>
    <comment_count>3</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2022-07-30 01:23:02 -0700</bug_when>
    <thetext>Ah, probably the current implementation is enough optimized for the attached benchmark&apos;s pattern.
Two code is actually doing a bit different thing.
The first one is holes. On the other hand, the second one is filled with undefined.
So,

&gt;&gt;&gt; 1 in new Array(30)
false
&gt;&gt;&gt; 1 in Array.from({length:30})
true

I wonder if we should optimize `({})[0]` case more. Currently, I think we are invoking  operationGetByVal.

Hottest bytecodes as &lt;numSamples   &apos;functionName#hash:JITType:bytecodeIndex&apos;&gt;
   900    &apos;operationGetByVal#&lt;nil&gt;:None:&lt;nil&gt;&apos;
   413    &apos;JSC::JSObject::getOwnPropertySlotByIndex(JSC::JSObject*, JSC::JSGlobalObject*, unsigned int, JSC::PropertySlot&amp;)#&lt;nil&gt;:None:&lt;nil&gt;&apos;
    61    &apos;from#&lt;nil&gt;:FTL:bc#368&apos;
    59    &apos;from#&lt;nil&gt;:FTL:bc#426&apos;
    44    &apos;JSC::JSArray::tryCreate(JSC::VM&amp;, JSC::Structure*, unsigned int, unsigned int)#&lt;nil&gt;:None:&lt;nil&gt;&apos;
     6    &apos;syscall_thread_switch#&lt;nil&gt;:None:&lt;nil&gt;&apos;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1887824</commentid>
    <comment_count>4</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2022-07-30 03:16:35 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/2876</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1888906</commentid>
    <comment_count>5</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2022-08-04 10:46:14 -0700</bug_when>
    <thetext>Committed 253120@main (801dcc1c9e7a): &lt;https://commits.webkit.org/253120@main&gt;

Reviewed commits have been landed. Closing PR #2876 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>459136</attachid>
            <date>2022-05-10 15:14:30 -0700</date>
            <delta_ts>2022-05-10 15:14:30 -0700</delta_ts>
            <desc>microbenchmark.js</desc>
            <filename>microbenchmark.js</filename>
            <type>text/javascript</type>
            <size>667</size>
            <attacher name="Jarred Sumner">jarred</attacher>
            
              <data encoding="base64">Ly8gVGhpcyBzaG91bGQgcnVuIGluIGJvdGggbm9kZSBhbmQganNjIHNoZWxsCnZhciB0aW1lID0K
ICAicHJlY2lzZVRpbWUiIGluIGdsb2JhbFRoaXMKICAgID8gKCkgPT4gZ2xvYmFsVGhpcy5wcmVj
aXNlVGltZSgpICogMTAwMAogICAgOiBwZXJmb3JtYW5jZS5ub3cuYmluZChwZXJmb3JtYW5jZSk7
Cgp2YXIgbG9nID0gInByaW50IiBpbiBnbG9iYWxUaGlzID8gZ2xvYmFsVGhpcy5wcmludCA6IGNv
bnNvbGUubG9nOwoKewogIGNvbnN0IHN0YXJ0ID0gdGltZSgpOwogIGZvciAobGV0IGkgPSAwOyBp
IDwgOTk7IGkrKykgbmV3IEFycmF5KDEwMjQgKiAxMDI0ICogMik7CgogIGxvZygKICAgIGBuZXcg
QXJyYXkoJHsxMDI0ICogMTAyNCAqIDJ9KTogJHtuZXcgSW50bC5OdW1iZXJGb3JtYXQoKS5mb3Jt
YXQoCiAgICAgIHRpbWUoKSAtIHN0YXJ0CiAgICApfW1zYAogICk7Cn0KCnsKICBjb25zdCBzdGFy
dCA9IHRpbWUoKTsKICBmb3IgKGxldCBpID0gMDsgaSA8IDk5OyBpKyspIEFycmF5LmZyb20oeyBs
ZW5ndGg6IDEwMjQgKiAxMDI0ICogMiB9KTsKCiAgbG9nKAogICAgYEFycmF5LmZyb20oe2xlbmd0
aDogJHsxMDI0ICogMTAyNCAqIDJ9fSk6ICR7bmV3IEludGwuTnVtYmVyRm9ybWF0KCkuZm9ybWF0
KAogICAgICB0aW1lKCkgLSBzdGFydAogICAgKX1tc2AKICApOwp9Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>