Bug 1075644 - Reduce Gecko thread priority at very start; r=snorp r=bnicholson

This commit is contained in:
Jim Chen 2014-10-20 12:55:30 -04:00
parent d149f76f6a
commit 6029c93b00
4 changed files with 16 additions and 9 deletions

View File

@ -1254,6 +1254,11 @@ public abstract class GeckoApp
}, 1000 * 5 /* 5 seconds */); }, 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();
Bundle stateBundle = getIntent().getBundleExtra(EXTRA_STATE_BUNDLE); Bundle stateBundle = getIntent().getBundleExtra(EXTRA_STATE_BUNDLE);
if (stateBundle != null) { if (stateBundle != null) {
// Use the state bundle if it was given as an intent extra. This is // Use the state bundle if it was given as an intent extra. This is
@ -1630,6 +1635,10 @@ public abstract class GeckoApp
} else if (NotificationHelper.HELPER_BROADCAST_ACTION.equals(action)) { } else if (NotificationHelper.HELPER_BROADCAST_ACTION.equals(action)) {
NotificationHelper.getInstance(getApplicationContext()).handleNotificationIntent(intent); 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 { private String restoreSessionTabs(final boolean isExternalURL) throws SessionRestoreException {

View File

@ -51,6 +51,7 @@ public class GeckoThread extends Thread implements GeckoEventListener {
if (isCreated()) if (isCreated())
return false; return false;
sGeckoThread = new GeckoThread(sArgs, sAction, sUri); sGeckoThread = new GeckoThread(sArgs, sAction, sUri);
ThreadUtils.sGeckoThread = sGeckoThread;
return true; return true;
} }
@ -164,7 +165,6 @@ public class GeckoThread extends Thread implements GeckoEventListener {
@Override @Override
public void run() { public void run() {
Looper.prepare(); Looper.prepare();
ThreadUtils.sGeckoThread = this;
ThreadUtils.sGeckoHandler = new Handler(); ThreadUtils.sGeckoHandler = new Handler();
ThreadUtils.sGeckoQueue = Looper.myQueue(); ThreadUtils.sGeckoQueue = Looper.myQueue();

View File

@ -98,9 +98,6 @@ public class TopSitesPanel extends HomeFragment {
// Max number of entries shown in the grid from the cursor. // Max number of entries shown in the grid from the cursor.
private int mMaxGridEntries; 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() { public static TopSitesPanel newInstance() {
return new TopSitesPanel(); return new TopSitesPanel();
} }
@ -347,7 +344,7 @@ public class TopSitesPanel extends HomeFragment {
// appear, especially during startup (bug 897162). By minimizing the // appear, especially during startup (bug 897162). By minimizing the
// Gecko thread priority, we ensure that the UI appears quickly. The // Gecko thread priority, we ensure that the UI appears quickly. The
// priority is reset to normal once thumbnails are loaded. // priority is reset to normal once thumbnails are loaded.
ThreadUtils.reduceGeckoPriority(PRIORITY_RESET_TIMEOUT); ThreadUtils.reduceGeckoPriority();
} }
/** /**

View File

@ -17,6 +17,9 @@ import android.util.Log;
public final class ThreadUtils { public final class ThreadUtils {
private static final String LOGTAG = "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 * Controls the action taken when a method like
* {@link ThreadUtils#assertOnUiThread(AssertBehavior)} detects a problem. * {@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 * Note that there are no guards in place to prevent multiple calls
* to this method from conflicting with each other. * 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) { if (Runtime.getRuntime().availableProcessors() > 1) {
// Don't reduce priority for multicore devices. We use availableProcessors() // Don't reduce priority for multicore devices. We use availableProcessors()
// for its fast performance. It may give false negatives (i.e. multicore // for its fast performance. It may give false negatives (i.e. multicore
@ -222,7 +223,7 @@ public final class ThreadUtils {
if (!sIsGeckoPriorityReduced && sGeckoThread != null) { if (!sIsGeckoPriorityReduced && sGeckoThread != null) {
sIsGeckoPriorityReduced = true; sIsGeckoPriorityReduced = true;
sGeckoThread.setPriority(Thread.MIN_PRIORITY); sGeckoThread.setPriority(Thread.MIN_PRIORITY);
getUiHandler().postDelayed(sPriorityResetRunnable, timeout); getUiHandler().postDelayed(sPriorityResetRunnable, PRIORITY_RESET_TIMEOUT);
} }
} }