Bug 1292218 - Run collectors more in reftests. r=jmaher draft
authorAndrew McCreight <continuation@gmail.com>
Thu, 04 Aug 2016 08:03:25 -0700
changeset 402708 cfe24d5d0d8b6ea58e9e7abf8cb47268169af0a6
parent 400444 6e191a55c3d23e83e6a2e72e4e80c1dc21516493
child 528751 908d3c2aaec7c77c8a59ac302ba55aa549c5bb99
push id26744
push userbmo:continuation@gmail.com
push dateThu, 18 Aug 2016 18:51:17 +0000
reviewersjmaher
bugs1292218
milestone51.0a1
Bug 1292218 - Run collectors more in reftests. r=jmaher MozReview-Commit-ID: E7TQpBMeiVB
layout/tools/reftest/reftest-content.js
--- a/layout/tools/reftest/reftest-content.js
+++ b/layout/tools/reftest/reftest-content.js
@@ -1,14 +1,16 @@
 /* -*- indent-tabs-mode: nil; js-indent-level: 4 -*- /
 /* vim: set shiftwidth=4 tabstop=8 autoindent cindent expandtab: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+// This file is used both for e10s and non-e10s reftests.
+
 var CC = Components.classes;
 const CI = Components.interfaces;
 const CR = Components.results;
 const CU = Components.utils;
 
 const XHTML_NS = "http://www.w3.org/1999/xhtml";
 
 const DEBUG_CONTRACTID = "@mozilla.org/xpcom/debug;1";
@@ -682,16 +684,37 @@ function OnDocumentLoad(event)
     }
 
     if (currentDoc.location.href != gCurrentURL) {
         LogInfo("OnDocumentLoad fired for previous document");
         // Ignore load events for previous documents.
         return;
     }
 
+    // Reftests open and close windows very quickly, so that the usual
+    // browser heuristics for running the garbage collector (GC) and
+    // cycle collector (CC) do not work well. This causes memory usage
+    // to increase, which can cause tests to run out of memory, or
+    // time out because we end up freeing many windows at once during
+    // a test, which can take a long time.
+    //
+    // To combat this, call |runNextCollectorTimer();| a few
+    // times. This makes us run incremental GC or CC more eagerly,
+    // reducing memory usage, while ensuring that we are still
+    // somewhat testing incremental collection.
+    //
+    // There's no specific reason for calling this four times in a
+    // row, other than it seemed to help more than calling it less
+    // times, and it helped as much as calling it five times. Each
+    // call should only take 5ms to 40ms.
+    windowUtils().runNextCollectorTimer();
+    windowUtils().runNextCollectorTimer();
+    windowUtils().runNextCollectorTimer();
+    windowUtils().runNextCollectorTimer();
+
     // Collect all editable, spell-checked elements.  It may be the case that
     // not all the elements that match this selector will be spell checked: for
     // example, a textarea without a spellcheck attribute may have a parent with
     // spellcheck=false, or script may set spellcheck=false on an element whose
     // markup sets it to true.  But that's OK since onSpellCheck detects the
     // absence of spell checking, too.
     var querySelector =
         '*[class~="spell-checked"],' +