Bug 1489572 - Add LifoAlloc heuristic to increase the reserved space based on the consumed space. r=jorendorff
☠☠ backed out by 58bcea5ede75 ☠ ☠
authorNicolas B. Pierron <nicolas.b.pierron@nbp.name>
Fri, 19 Oct 2018 17:58:07 +0200
changeset 490861 f3aa68c506e01055a7d7d20eb4fb672c511b9caf
parent 490860 cbfcb4b2b5c93b1d7330c6869fa197be79ea37f4
child 490865 fd8c2dda33fccca55c84453205efbca498b906cb
push id247
push userfmarier@mozilla.com
push dateSat, 27 Oct 2018 01:06:44 +0000
reviewersjorendorff
bugs1489572
milestone65.0a1
Bug 1489572 - Add LifoAlloc heuristic to increase the reserved space based on the consumed space. r=jorendorff
js/src/ds/LifoAlloc.cpp
--- a/js/src/ds/LifoAlloc.cpp
+++ b/js/src/ds/LifoAlloc.cpp
@@ -161,17 +161,26 @@ MallocGoodSize(size_t aSize)
 }
 
 // Heuristic to choose the size of the next BumpChunk for small allocations.
 // `start` is the size of the first chunk. `used` is the total size of all
 // BumpChunks in this LifoAlloc so far.
 static size_t
 NextSize(size_t start, size_t used)
 {
-    return start;
+    // Double the size, up to 1 MB.
+    const size_t mb = 1 * 1024 * 1024;
+    if (used < mb) {
+        return Max(start, used);
+    }
+
+    // After 1 MB, grow more gradually, to waste less memory.
+    // The sequence (in megabytes) begins:
+    // 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, ...
+    return JS_ROUNDUP(used / 8, mb);
 }
 
 LifoAlloc::UniqueBumpChunk
 LifoAlloc::newChunkWithCapacity(size_t n, bool oversize)
 {
     MOZ_ASSERT(fallibleScope_, "[OOM] Cannot allocate a new chunk in an infallible scope.");
 
     // Compute the size which should be requested in order to be able to fit |n|