diff --git a/app/src/main/java/org/mozilla/fenix/components/Core.kt b/app/src/main/java/org/mozilla/fenix/components/Core.kt index 65ccf94a7e..687289338f 100644 --- a/app/src/main/java/org/mozilla/fenix/components/Core.kt +++ b/app/src/main/java/org/mozilla/fenix/components/Core.kt @@ -293,14 +293,14 @@ class Core( // Use these for startup-path code, where we don't want to do any work that's not strictly necessary. // For example, this is how the GeckoEngine delegates (history, logins) are configured. // We can fully initialize GeckoEngine without initialized our storage. - val lazyHistoryStorage = lazy { PlacesHistoryStorage(context, crashReporter) } - val lazyBookmarksStorage = lazy { PlacesBookmarksStorage(context) } - val lazyPasswordsStorage = lazy { SyncableLoginsStorage(context, passwordsEncryptionKey) } + val lazyHistoryStorage = lazyMonitored { PlacesHistoryStorage(context, crashReporter) } + val lazyBookmarksStorage = lazyMonitored { PlacesBookmarksStorage(context) } + val lazyPasswordsStorage = lazyMonitored { SyncableLoginsStorage(context, passwordsEncryptionKey) } /** * The storage component to sync and persist tabs in a Firefox Sync account. */ - val lazyRemoteTabsStorage = lazy { RemoteTabsStorage() } + val lazyRemoteTabsStorage = lazyMonitored { RemoteTabsStorage() } // For most other application code (non-startup), these wrappers are perfectly fine and more ergonomic. val historyStorage by lazyMonitored { lazyHistoryStorage.value } diff --git a/app/src/main/java/org/mozilla/fenix/perf/LazyMonitored.kt b/app/src/main/java/org/mozilla/fenix/perf/LazyMonitored.kt index d8ec7a96d8..d9efde5f7a 100644 --- a/app/src/main/java/org/mozilla/fenix/perf/LazyMonitored.kt +++ b/app/src/main/java/org/mozilla/fenix/perf/LazyMonitored.kt @@ -27,7 +27,7 @@ fun lazyMonitored(initializer: () -> T) = LazyMonitored(initializer) * For example, we can count the number of components initialized to see how the number of * components initialized on start up impacts start up time. */ -class LazyMonitored(initializer: () -> T) { +class LazyMonitored(initializer: () -> T) : Lazy { // Lazy is thread safe. private val lazyValue = lazy { // We're unlikely to have 4 billion components so we don't handle overflow. @@ -40,5 +40,6 @@ class LazyMonitored(initializer: () -> T) { } } - operator fun getValue(thisRef: Any?, property: KProperty<*>): T = lazyValue.value + override val value: T get() = lazyValue.value + override fun isInitialized(): Boolean = lazyValue.isInitialized() }