From a896b47cfe7be8fb7039fe692295419e2c5bee9e Mon Sep 17 00:00:00 2001 From: Michael Comella Date: Mon, 20 Jan 2020 18:19:10 -0800 Subject: [PATCH] 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. --- .../main/java/org/mozilla/fenix/FenixApplication.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt index c181a8a34..80253554c 100644 --- a/app/src/main/java/org/mozilla/fenix/FenixApplication.kt +++ b/app/src/main/java/org/mozilla/fenix/FenixApplication.kt @@ -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(