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

This commit is contained in:
Jim Chen 2014-10-06 13:23:53 -04:00
parent 7c6f4c2def
commit 223e526147
4 changed files with 16 additions and 9 deletions

View File

@ -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 {

View File

@ -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();

View File

@ -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();
}
/**

View File

@ -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);
}
}