Commit a896b47c authored by Michael Comella's avatar Michael Comella Committed by Jeff Boek
Browse files

For #7820: warm BrowsersCache on background thread.

In an early iteration of his patch on a beta build, I saw no improvement over
6 runs (Pixel 2):
- Before: 401.5ms
- After: 402.17ms

This may be attributed to noise in startup performance. However,
BrowsersCache disappears from profiles completely and results in
theoretical performance gains.

When using the StartupTimeline class (not landed yet), I see a 27.75ms
runtime improvement on beta builds after this patch.
parent a42ad760
......@@ -37,6 +37,7 @@ import org.mozilla.fenix.components.Components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.session.NotificationSessionObserver
import org.mozilla.fenix.session.VisibilityLifecycleCallback
import org.mozilla.fenix.utils.BrowsersCache
@SuppressLint("Registered")
@Suppress("TooManyFunctions")
......@@ -104,6 +105,7 @@ open class FenixApplication : LocaleAwareApplication() {
setDayNightTheme()
enableStrictMode()
warmBrowsersCache()
// Enable the service-experiments component
if (settings().isExperimentationEnabled && Config.channel.isReleaseOrBeta) {
......@@ -260,6 +262,14 @@ open class FenixApplication : LocaleAwareApplication() {
}
}
private fun warmBrowsersCache() {
// We avoid blocking the main thread for BrowsersCache on startup by loading it on
// background thread.
GlobalScope.launch(Dispatchers.Default) {
BrowsersCache.all(this@FenixApplication)
}
}
private fun enableStrictMode() {
if (Config.channel.isDebug) {
StrictMode.setThreadPolicy(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment