Ignore:
Timestamp:
Sep 22, 2017, 1:22:44 AM (8 years ago)
Author:
Yusuke Suzuki
Message:

[DFG][FTL] Profile array vector length for array allocation
https://bugs.webkit.org/show_bug.cgi?id=177051

Reviewed by Saam Barati.

JSTests:

  • microbenchmarks/new-array-buffer-vector-profile.js: Added.

(target):

Source/JavaScriptCore:

Currently, NewArrayBuffer allocation is penalized by JSC: While empty array gets 25 vector size (BASE_CONTIGUOUS_VECTOR_LEN),
new_array_buffer case gets 3 vector size (BASE_CONTIGUOUS_VECTOR_LEN). Surely, new_array_buffer can get larger vector size
if the number of its constant elements is larger than 3. But these created array may be grown by push() operation after
the allocation. In this case, new_array_buffer is penalized compared to empty array allocation.

empty array allocation,

var array = [];
array.push(0);
array.push(1);
array.push(2);
array.push(3);
array.push(4);

v.s. new_array_buffer case,

var array = [0];
array.push(1);
array.push(2);
array.push(3);
array.push(4);

In this case, the latter becomes slow. While we have a chance to reduce memory usage if new_array_buffer is not grown (and a bit likely),
we should allocate 3 to 25 vector size if it is likely grown. So we should get profile on the resulted array.

We select 25 to make it fit to one of size classes.

In this patch, we extend ArrayAllocationProfile to record vector length. And use this information when allocating array for new_array_buffer.
If the number of new_array_buffer constants is <= 25, array vector size would become 3 to 25 based on profiling. If the number of its constants
is larger than 25, we just use it for allocation as before.

Added microbenchmark and SixSpeed spread-literal.es5 shows improvement.

new-array-buffer-vector-profile 67.4706+-3.7625 28.4249+-1.9025 definitely 2.3736x faster
spread-literal.es5 133.1443+-9.2253 95.2667+-0.5740 definitely 1.3976x faster

  • bytecode/ArrayAllocationProfile.cpp:

(JSC::ArrayAllocationProfile::updateProfile):
(JSC::ArrayAllocationProfile::updateIndexingType): Deleted.

  • bytecode/ArrayAllocationProfile.h:

(JSC::ArrayAllocationProfile::selectIndexingType):
(JSC::ArrayAllocationProfile::vectorLengthHint):
(JSC::ArrayAllocationProfile::ArrayAllocationProfile): Deleted.

  • bytecode/CodeBlock.cpp:

(JSC::CodeBlock::updateAllArrayPredictions):

  • dfg/DFGByteCodeParser.cpp:

(JSC::DFG::ByteCodeParser::parseBlock):

  • dfg/DFGGraph.cpp:

(JSC::DFG::Graph::dump):

  • dfg/DFGNode.h:

(JSC::DFG::Node::vectorLengthHint):

  • dfg/DFGOperations.cpp:
  • dfg/DFGOperations.h:
  • dfg/DFGSpeculativeJIT64.cpp:

(JSC::DFG::SpeculativeJIT::compile):

  • ftl/FTLLowerDFGToB3.cpp:

(JSC::FTL::DFG::LowerDFGToB3::compileArraySlice):
(JSC::FTL::DFG::LowerDFGToB3::compileNewArrayBuffer):
(JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSize):
(JSC::FTL::DFG::LowerDFGToB3::allocateJSArray):
(JSC::FTL::DFG::LowerDFGToB3::allocateUninitializedContiguousJSArrayInternal):
(JSC::FTL::DFG::LowerDFGToB3::allocateUninitializedContiguousJSArray):

  • runtime/ArrayConventions.h:
  • runtime/JSArray.h:

(JSC::JSArray::tryCreate):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r222356 r222380  
     12017-09-21  Yusuke Suzuki  <[email protected]>
     2
     3        [DFG][FTL] Profile array vector length for array allocation
     4        https://bugs.webkit.org/show_bug.cgi?id=177051
     5
     6        Reviewed by Saam Barati.
     7
     8        Currently, NewArrayBuffer allocation is penalized by JSC: While empty array gets 25 vector size (BASE_CONTIGUOUS_VECTOR_LEN),
     9        new_array_buffer case gets 3 vector size (BASE_CONTIGUOUS_VECTOR_LEN). Surely, new_array_buffer can get larger vector size
     10        if the number of its constant elements is larger than 3. But these created array may be grown by `push()` operation after
     11        the allocation. In this case, new_array_buffer is penalized compared to empty array allocation.
     12
     13            empty array allocation,
     14
     15            var array = [];
     16            array.push(0);
     17            array.push(1);
     18            array.push(2);
     19            array.push(3);
     20            array.push(4);
     21
     22            v.s. new_array_buffer case,
     23
     24            var array = [0];
     25            array.push(1);
     26            array.push(2);
     27            array.push(3);
     28            array.push(4);
     29
     30        In this case, the latter becomes slow. While we have a chance to reduce memory usage if new_array_buffer is not grown (and a bit likely),
     31        we should allocate 3 to 25 vector size if it is likely grown. So we should get profile on the resulted array.
     32
     33        We select 25 to make it fit to one of size classes.
     34
     35        In this patch, we extend ArrayAllocationProfile to record vector length. And use this information when allocating array for new_array_buffer.
     36        If the number of new_array_buffer constants is <= 25, array vector size would become 3 to 25 based on profiling. If the number of its constants
     37        is larger than 25, we just use it for allocation as before.
     38
     39        Added microbenchmark and SixSpeed spread-literal.es5 shows improvement.
     40
     41            new-array-buffer-vector-profile       67.4706+-3.7625     ^     28.4249+-1.9025        ^ definitely 2.3736x faster
     42            spread-literal.es5                   133.1443+-9.2253     ^     95.2667+-0.5740        ^ definitely 1.3976x faster
     43
     44        * bytecode/ArrayAllocationProfile.cpp:
     45        (JSC::ArrayAllocationProfile::updateProfile):
     46        (JSC::ArrayAllocationProfile::updateIndexingType): Deleted.
     47        * bytecode/ArrayAllocationProfile.h:
     48        (JSC::ArrayAllocationProfile::selectIndexingType):
     49        (JSC::ArrayAllocationProfile::vectorLengthHint):
     50        (JSC::ArrayAllocationProfile::ArrayAllocationProfile): Deleted.
     51        * bytecode/CodeBlock.cpp:
     52        (JSC::CodeBlock::updateAllArrayPredictions):
     53        * dfg/DFGByteCodeParser.cpp:
     54        (JSC::DFG::ByteCodeParser::parseBlock):
     55        * dfg/DFGGraph.cpp:
     56        (JSC::DFG::Graph::dump):
     57        * dfg/DFGNode.h:
     58        (JSC::DFG::Node::vectorLengthHint):
     59        * dfg/DFGOperations.cpp:
     60        * dfg/DFGOperations.h:
     61        * dfg/DFGSpeculativeJIT64.cpp:
     62        (JSC::DFG::SpeculativeJIT::compile):
     63        * ftl/FTLLowerDFGToB3.cpp:
     64        (JSC::FTL::DFG::LowerDFGToB3::compileArraySlice):
     65        (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayBuffer):
     66        (JSC::FTL::DFG::LowerDFGToB3::compileNewArrayWithSize):
     67        (JSC::FTL::DFG::LowerDFGToB3::allocateJSArray):
     68        (JSC::FTL::DFG::LowerDFGToB3::allocateUninitializedContiguousJSArrayInternal):
     69        (JSC::FTL::DFG::LowerDFGToB3::allocateUninitializedContiguousJSArray):
     70        * runtime/ArrayConventions.h:
     71        * runtime/JSArray.h:
     72        (JSC::JSArray::tryCreate):
     73
    1742017-09-21  Joseph Pecoraro  <[email protected]>
    275
Note: See TracChangeset for help on using the changeset viewer.