Bug 1353013 - Be less aggressive about preloading about:newtab. r=florian

Based on a patch that Dão Gottwald <dao+bmo@mozilla.com> wrote.

We used to preload about:newtab as soon as a tab had finished being opened,
which meant that the first opened tab was _never_ preloaded, and that we
risked janking the browser immediately after the user opened a new tab
(which is, arguably, the worst time to do it, since the user is probably
about to navigate that tab somewhere).

This patch makes it so that about:newtab is preloaded after:

1) 1 second of user inactivity, and
2) When we have at least 40ms of idle time to spend in an idle callback.

The 1s and 40ms thresholds were chosen arbitrarily, and we might tune them
over time.

MozReview-Commit-ID: J5xkPQvCdW6

--HG--
extra : rebase_source : 51aed2f47ee5c6a68d04036d0bdc9e6357a5fc8d
This commit is contained in:
Mike Conley 2017-08-24 15:23:18 -07:00
Родитель 7298681f5c
Коммит ec416a2990
4 изменённых файлов: 52 добавлений и 1 удалений

Просмотреть файл

@ -1590,6 +1590,9 @@ var gBrowserInit = {
}
});
// Prepare preloaded browser for the next new tab to open.
gBrowser.requestPreloadBrowser();
this.delayedStartupFinished = true;
_resolveDelayedStartup();

Просмотреть файл

@ -2099,6 +2099,40 @@
</body>
</method>
<field name="_preloadBrowserMinUserIdleSeconds">1</field>
<field name="_preloadBrowserMinIdlePeriodMs">40</field>
<method name="requestPreloadBrowser">
<body><![CDATA[
// Do nothing if we have a preloaded browser already or we're about
// to create one or preloading is disabled.
if (this._preloadedBrowser ||
this._preloadBrowserIdleObserver ||
!this._isPreloadingEnabled()) {
return;
}
this._preloadBrowserIdleObserver = (aSubject, aTopic) => {
if (aTopic != "idle") {
return;
}
Services.idle.removeIdleObserver(this._preloadBrowserIdleObserver,
this._preloadBrowserMinUserIdleSeconds);
this._preloadBrowserIdleObserver = null;
let idleCallback = deadline => {
if (deadline.timeRemaining() < this._preloadBrowserMinIdlePeriodMs) {
window.requestIdleCallback(idleCallback);
} else {
this._createPreloadBrowser();
}
};
window.requestIdleCallback(idleCallback);
};
Services.idle.addIdleObserver(this._preloadBrowserIdleObserver, this._preloadBrowserMinUserIdleSeconds);
]]></body>
</method>
<method name="_createPreloadBrowser">
<body>
<![CDATA[
@ -2108,6 +2142,12 @@
return;
}
if (this._preloadBrowserIdleObserver) {
Services.idle.removeIdleObserver(this._preloadBrowserIdleObserver,
this._preloadBrowserMinUserIdleSeconds);
this._preloadBrowserIdleObserver = null;
}
let remoteType =
E10SUtils.getRemoteTypeForURI(BROWSER_NEW_TAB_URL,
gMultiProcessBrowser);
@ -5854,6 +5894,12 @@
}
Services.prefs.removeObserver("accessibility.typeaheadfind", this);
if (this._preloadBrowserIdleObserver) {
Services.idle.removeIdleObserver(this._preloadBrowserIdleObserver,
this._preloadBrowserMinUserIdleSeconds);
this._preloadBrowserIdleObserver = null;
}
]]>
</destructor>
@ -6925,7 +6971,7 @@
this.mTabstrip._updateScrollButtonsDisabledState();
// Preload the next about:newtab if there isn't one already.
this.tabbrowser._createPreloadBrowser();
this.tabbrowser.requestPreloadBrowser();
]]></body>
</method>

Просмотреть файл

@ -77,6 +77,7 @@ var initTable = {
droppedLinkHandler: ["@mozilla.org/content/dropped-link-handler;1", "nsIDroppedLinkHandler"],
els: ["@mozilla.org/eventlistenerservice;1", "nsIEventListenerService"],
eTLD: ["@mozilla.org/network/effective-tld-service;1", "nsIEffectiveTLDService"],
idle: ["@mozilla.org/widget/idleservice;1", "nsIIdleService"],
intl: ["@mozilla.org/mozintl;1", "mozIMozIntl"],
locale: ["@mozilla.org/intl/localeservice;1", "mozILocaleService"],
logins: ["@mozilla.org/login-manager;1", "nsILoginManager"],

Просмотреть файл

@ -42,6 +42,7 @@ function run_test() {
checkService("droppedLinkHandler", Ci.nsIDroppedLinkHandler);
checkService("eTLD", Ci.nsIEffectiveTLDService);
checkService("focus", Ci.nsIFocusManager);
checkService("idle", Ci.nsIIdleService);
checkService("io", Ci.nsIIOService);
checkService("io", Ci.nsIIOService2);
checkService("intl", Ci.mozIMozIntl);