Bug 947025 - Limit the time spent in RunLoader to avoid chrome hang. r=roc
authorJohn Daggett <jdaggett@mozilla.com>
Fri, 06 Dec 2013 12:47:46 +0900
changeset 173801 dba508605c1b4c40ff47436d5a345b67e7b38074
parent 173800 b395bc2b9ba9aa3654a0a4a31ac12aedd0ca813b
child 173802 dee18b5520fb04844f0c703274720a706d138331
push id3224
push userlsblakk@mozilla.com
push dateTue, 04 Feb 2014 01:06:49 +0000
treeherdermozilla-beta@60c04d0987f1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs947025
milestone28.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 947025 - Limit the time spent in RunLoader to avoid chrome hang. r=roc
gfx/thebes/gfxPlatformFontList.cpp
--- a/gfx/thebes/gfxPlatformFontList.cpp
+++ b/gfx/thebes/gfxPlatformFontList.cpp
@@ -684,19 +684,22 @@ gfxPlatformFontList::RemoveCmap(const gf
 void 
 gfxPlatformFontList::InitLoader()
 {
     GetFontFamilyList(mFontFamiliesToLoad);
     mStartIndex = 0;
     mNumFamilies = mFontFamiliesToLoad.Length();
 }
 
+#define FONT_LOADER_MAX_TIMESLICE 100  // max time for one pass through RunLoader = 100ms
+
 bool
 gfxPlatformFontList::RunLoader()
 {
+    TimeStamp start = TimeStamp::Now();
     uint32_t i, endIndex = (mStartIndex + mIncrement < mNumFamilies ? mStartIndex + mIncrement : mNumFamilies);
     bool loadCmaps = !UsesSystemFallback() ||
         gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
 
     // for each font family, load in various font info
     for (i = mStartIndex; i < endIndex; i++) {
         gfxFontFamily* familyEntry = mFontFamiliesToLoad[i];
 
@@ -715,16 +718,24 @@ gfxPlatformFontList::RunLoader()
             familyEntry->ReadAllCMAPs();
         }
 
         // read in face names
         familyEntry->ReadFaceNames(this, NeedFullnamePostscriptNames());
 
         // check whether the family can be considered "simple" for style matching
         familyEntry->CheckForSimpleFamily();
+
+        // limit the time spent reading fonts in one pass
+        TimeDuration elapsed = TimeStamp::Now() - start;
+        if (elapsed.ToMilliseconds() > FONT_LOADER_MAX_TIMESLICE &&
+                i + 1 != endIndex) {
+            endIndex = i + 1;
+            break;
+        }
     }
 
     mStartIndex = endIndex;
 
     return (mStartIndex >= mNumFamilies);
 }
 
 void