From 223e52614768cc1a8ec43b0e4aec5a25cfa484d1 Mon Sep 17 00:00:00 2001 From: Jim Chen Date: Mon, 6 Oct 2014 13:23:53 -0400 Subject: [PATCH] Bug 1075644 - Reduce Gecko thread priority at very start; r=snorp r=bnicholson --- mobile/android/base/GeckoApp.java | 9 +++++++++ mobile/android/base/GeckoThread.java | 2 +- mobile/android/base/home/TopSitesPanel.java | 5 +---- mobile/android/base/util/ThreadUtils.java | 9 +++++---- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/mobile/android/base/GeckoApp.java b/mobile/android/base/GeckoApp.java index cf7bf4e8d19..2b41ad8a4e3 100644 --- a/mobile/android/base/GeckoApp.java +++ b/mobile/android/base/GeckoApp.java @@ -1229,6 +1229,11 @@ public abstract class GeckoApp }, 1000 * 5 /* 5 seconds */); } + // Heavy load on the Gecko thread can slow down the time it takes for UI to appear on + // single-core devices. By minimizing the Gecko thread priority, we ensure that the UI + // appears quickly. The priority is reset to normal once thumbnails are loaded. + ThreadUtils.reduceGeckoPriority(); + MemoryMonitor.getInstance().init(getApplicationContext()); Tabs.getInstance().attachToContext(this); @@ -1605,6 +1610,10 @@ public abstract class GeckoApp } else if (NotificationHelper.HELPER_BROADCAST_ACTION.equals(action)) { NotificationHelper.getInstance(getApplicationContext()).handleNotificationIntent(intent); } + + // Reset Gecko to normal priority. We may reduce the + // priority again later, e.g. for loading thumbnails. + ThreadUtils.resetGeckoPriority(); } private String restoreSessionTabs(final boolean isExternalURL) throws SessionRestoreException { diff --git a/mobile/android/base/GeckoThread.java b/mobile/android/base/GeckoThread.java index 0b424f4cecb..89ec623cee8 100644 --- a/mobile/android/base/GeckoThread.java +++ b/mobile/android/base/GeckoThread.java @@ -51,6 +51,7 @@ public class GeckoThread extends Thread implements GeckoEventListener { if (isCreated()) return false; sGeckoThread = new GeckoThread(sArgs, sAction, sUri); + ThreadUtils.sGeckoThread = sGeckoThread; return true; } @@ -164,7 +165,6 @@ public class GeckoThread extends Thread implements GeckoEventListener { @Override public void run() { Looper.prepare(); - ThreadUtils.sGeckoThread = this; ThreadUtils.sGeckoHandler = new Handler(); ThreadUtils.sGeckoQueue = Looper.myQueue(); diff --git a/mobile/android/base/home/TopSitesPanel.java b/mobile/android/base/home/TopSitesPanel.java index 26ea3f154b5..66754fbb3a0 100644 --- a/mobile/android/base/home/TopSitesPanel.java +++ b/mobile/android/base/home/TopSitesPanel.java @@ -98,9 +98,6 @@ public class TopSitesPanel extends HomeFragment { // Max number of entries shown in the grid from the cursor. private int mMaxGridEntries; - // Time in ms until the Gecko thread is reset to normal priority. - private static final long PRIORITY_RESET_TIMEOUT = 10000; - public static TopSitesPanel newInstance() { return new TopSitesPanel(); } @@ -347,7 +344,7 @@ public class TopSitesPanel extends HomeFragment { // appear, especially during startup (bug 897162). By minimizing the // Gecko thread priority, we ensure that the UI appears quickly. The // priority is reset to normal once thumbnails are loaded. - ThreadUtils.reduceGeckoPriority(PRIORITY_RESET_TIMEOUT); + ThreadUtils.reduceGeckoPriority(); } /** diff --git a/mobile/android/base/util/ThreadUtils.java b/mobile/android/base/util/ThreadUtils.java index 90043b589ee..a61e5d174e4 100644 --- a/mobile/android/base/util/ThreadUtils.java +++ b/mobile/android/base/util/ThreadUtils.java @@ -17,6 +17,9 @@ import android.util.Log; public final class ThreadUtils { private static final String LOGTAG = "ThreadUtils"; + // Time in ms until the Gecko thread is reset to normal priority. + private static final long PRIORITY_RESET_TIMEOUT = 10000; + /** * Controls the action taken when a method like * {@link ThreadUtils#assertOnUiThread(AssertBehavior)} detects a problem. @@ -209,10 +212,8 @@ public final class ThreadUtils { * * Note that there are no guards in place to prevent multiple calls * to this method from conflicting with each other. - * - * @param timeout Timeout in ms after which the priority will be reset */ - public static void reduceGeckoPriority(long timeout) { + public static void reduceGeckoPriority() { if (Runtime.getRuntime().availableProcessors() > 1) { // Don't reduce priority for multicore devices. We use availableProcessors() // for its fast performance. It may give false negatives (i.e. multicore @@ -222,7 +223,7 @@ public final class ThreadUtils { if (!sIsGeckoPriorityReduced && sGeckoThread != null) { sIsGeckoPriorityReduced = true; sGeckoThread.setPriority(Thread.MIN_PRIORITY); - getUiHandler().postDelayed(sPriorityResetRunnable, timeout); + getUiHandler().postDelayed(sPriorityResetRunnable, PRIORITY_RESET_TIMEOUT); } }