Bug 1038038 - Part 2: Compute sizeLog2 in ShapeTable::init() better. r=bhackett, a=2.0+
authorNicholas Nethercote <nnethercote@mozilla.com>
Sun, 13 Jul 2014 23:29:50 -0700
changeset 208027 d94467fc9adee8f45a1b5e1cdbd127b1e2924450
parent 208026 e12c32a65348691eb88f4f5ca88127eb0b8ffa24
child 208028 41d971477d80f77b81973b83f8ac0aaacd4e2a58
push id3741
push userasasaki@mozilla.com
push dateMon, 21 Jul 2014 20:25:18 +0000
treeherdermozilla-beta@4d6f46f5af68 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbhackett, 2
bugs1038038
milestone32.0a2
Bug 1038038 - Part 2: Compute sizeLog2 in ShapeTable::init() better. r=bhackett, a=2.0+ For exapmle, currently if you have an entryCount of 9 you end up with a capacity of 32, when 16 would be more appropriate.
js/src/vm/Shape.cpp
--- a/js/src/vm/Shape.cpp
+++ b/js/src/vm/Shape.cpp
@@ -31,24 +31,20 @@ using namespace js::gc;
 using mozilla::CeilingLog2Size;
 using mozilla::DebugOnly;
 using mozilla::PodZero;
 using mozilla::RotateLeft;
 
 bool
 ShapeTable::init(ThreadSafeContext *cx, Shape *lastProp)
 {
-    /*
-     * Either we're creating a table for a large scope that was populated
-     * via property cache hit logic under JSOP_INITPROP, JSOP_SETNAME, or
-     * JSOP_SETPROP; or else calloc failed at least once already. In any
-     * event, let's try to grow, overallocating to hold at least twice the
-     * current population.
-     */
-    uint32_t sizeLog2 = CeilingLog2Size(2 * entryCount);
+    uint32_t sizeLog2 = CeilingLog2Size(entryCount);
+    uint32_t size = JS_BIT(sizeLog2);
+    if (entryCount >= size - (size >> 2))
+        sizeLog2++;
     if (sizeLog2 < MIN_SIZE_LOG2)
         sizeLog2 = MIN_SIZE_LOG2;
 
     /*
      * Use rt->calloc_ for memory accounting and overpressure handling
      * without OOM reporting. See ShapeTable::change.
      */
     entries = (Shape **) cx->calloc_(sizeOfEntries(JS_BIT(sizeLog2)));