Ignore:
Timestamp:
May 15, 2015, 1:02:26 PM (10 years ago)
Author:
[email protected]
Message:

JSArray::setLength() should reallocate instead of zero-filling if the reallocation would be small enough.
https://bugs.webkit.org/show_bug.cgi?id=144622

Reviewed by Geoffrey Garen.

When setting the array to a new length that is shorter, we now check if it is worth
just making a new butterfly instead of clearing out the slots in the old butterfly
that resides beyond the new length. If so, we will make a new butterfly instead.

There is no perf differences in the benchmark results. However, this does benefit
the perf of pathological cases where we need to shorten the length of a very large
array, as is the case in tests/mozilla/js1_5/Array/regress-101964.js. With this
patch, we can expect that test to complete in a short time again.

  • runtime/JSArray.cpp:

(JSC::JSArray::setLength):

  • runtime/JSObject.cpp:

(JSC::JSObject::reallocateAndShrinkButterfly):

  • makes a new butterfly with a new shorter length.
  • runtime/JSObject.h:
  • tests/mozilla/js1_5/Array/regress-101964.js:
  • Undo this test change since this patch will prevent us from spending a lot of time clearing a large butterfly.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSObject.cpp

    r184324 r184407  
    24582458}
    24592459
     2460void JSObject::reallocateAndShrinkButterfly(VM& vm, unsigned length)
     2461{
     2462    ASSERT(length < MAX_ARRAY_INDEX);
     2463    ASSERT(length < MAX_STORAGE_VECTOR_LENGTH);
     2464    ASSERT(hasContiguous(indexingType()) || hasInt32(indexingType()) || hasDouble(indexingType()) || hasUndecided(indexingType()));
     2465    ASSERT(m_butterfly->vectorLength() > length);
     2466    ASSERT(!m_butterfly->indexingHeader()->preCapacity(structure()));
     2467
     2468    DeferGC deferGC(vm.heap);
     2469    Butterfly* newButterfly = m_butterfly->resizeArray(vm, this, structure(), 0, ArrayStorage::sizeFor(length));
     2470    m_butterfly.set(vm, this, newButterfly);
     2471    m_butterfly->setVectorLength(length);
     2472    m_butterfly->setPublicLength(length);
     2473}
     2474
    24602475Butterfly* JSObject::growOutOfLineStorage(VM& vm, size_t oldSize, size_t newSize)
    24612476{
Note: See TracChangeset for help on using the changeset viewer.