Allocate the whole RegExpMatchesArray backing store up front.
authorakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Aug 2014 03:22:01 +0000 (03:22 +0000)
committerakling@apple.com <akling@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 15 Aug 2014 03:22:01 +0000 (03:22 +0000)
<https://webkit.org/b/135217>

We were using the generic array backing store allocation path for
RegExpMatchesArray which meant starting with 4 slots and then growing
it dynamically as we append. Since we always know the final number of
entries up front, allocate a perfectly-sized backing store right away.

~2% progression on Octane/regexp.

Reviewed by Geoffrey Garen.

* runtime/JSArray.h:
(JSC::createArrayButterflyWithExactLength):
* runtime/RegExpMatchesArray.cpp:
(JSC::RegExpMatchesArray::create):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@172618 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/JSArray.h
Source/JavaScriptCore/runtime/RegExpMatchesArray.cpp

index 891e2dd..ae0a803 100644 (file)
@@ -1,3 +1,22 @@
+2014-08-14  Andreas Kling  <akling@apple.com>
+
+        Allocate the whole RegExpMatchesArray backing store up front.
+        <https://webkit.org/b/135217>
+
+        We were using the generic array backing store allocation path for
+        RegExpMatchesArray which meant starting with 4 slots and then growing
+        it dynamically as we append. Since we always know the final number of
+        entries up front, allocate a perfectly-sized backing store right away.
+
+        ~2% progression on Octane/regexp.
+
+        Reviewed by Geoffrey Garen.
+
+        * runtime/JSArray.h:
+        (JSC::createArrayButterflyWithExactLength):
+        * runtime/RegExpMatchesArray.cpp:
+        (JSC::RegExpMatchesArray::create):
+
 2014-08-14  Saam Barati  <sbarati@apple.com>
 
         Allow high fidelity type profiling to be enabled and disabled.
index 70029e6..3e2b668 100644 (file)
@@ -190,6 +190,18 @@ inline Butterfly* createContiguousArrayButterfly(VM& vm, JSCell* intendedOwner,
     return result;
 }
 
+inline Butterfly* createArrayButterflyWithExactLength(VM& vm, JSCell* intendedOwner, unsigned initialLength)
+{
+    Butterfly* butterfly = Butterfly::create(
+        vm, intendedOwner, 0, 0, true, indexingHeaderForArray(initialLength, initialLength),
+        ArrayStorage::sizeFor(initialLength));
+    ArrayStorage* storage = butterfly->arrayStorage();
+    storage->m_indexBias = 0;
+    storage->m_sparseMap.clear();
+    storage->m_numValuesInVector = 0;
+    return butterfly;
+}
+
 inline Butterfly* createArrayButterfly(VM& vm, JSCell* intendedOwner, unsigned initialLength)
 {
     Butterfly* butterfly = Butterfly::create(
index 0c9e124..8cec4ea 100644 (file)
@@ -46,7 +46,7 @@ RegExpMatchesArray* RegExpMatchesArray::create(ExecState* exec, JSString* input,
 {
     ASSERT(result);
     VM& vm = exec->vm();
-    Butterfly* butterfly = createArrayButterfly(vm, 0, regExp->numSubpatterns() + 1);
+    Butterfly* butterfly = createArrayButterflyWithExactLength(vm, 0, regExp->numSubpatterns() + 1);
     RegExpMatchesArray* array = new (NotNull, allocateCell<RegExpMatchesArray>(vm.heap)) RegExpMatchesArray(vm, butterfly, exec->lexicalGlobalObject(), input, regExp, result);
     array->finishCreation(vm);
     return array;