From 9171209d44fedc8e1d4b177470fe408f2755980f Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Thu, 26 Mar 2026 15:20:38 -0400 Subject: [PATCH] Kickstart LRUCache to void constructor blocking in main thread --- .../main/java/com/vitorpamplona/amethyst/AppModules.kt | 8 ++++++++ .../com/vitorpamplona/amethyst/ui/StringResourceCache.kt | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt index 3f26f521d..7fe6b43bc 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/AppModules.kt @@ -25,6 +25,7 @@ import androidx.security.crypto.EncryptedSharedPreferences import coil3.disk.DiskCache import coil3.memory.MemoryCache import com.vitorpamplona.amethyst.commons.model.NoteState +import com.vitorpamplona.amethyst.commons.robohash.CachedRobohash import com.vitorpamplona.amethyst.model.Account import com.vitorpamplona.amethyst.model.LocalCache import com.vitorpamplona.amethyst.model.accountsCache.AccountCacheState @@ -62,6 +63,7 @@ import com.vitorpamplona.amethyst.service.relayClient.reqCommand.user.UserFinder import com.vitorpamplona.amethyst.service.relayClient.speedLogger.RelaySpeedLogger import com.vitorpamplona.amethyst.service.uploads.blossom.bud10.BlossomServerResolver import com.vitorpamplona.amethyst.service.uploads.nip95.Nip95CacheFactory +import com.vitorpamplona.amethyst.ui.resourceCacheInit import com.vitorpamplona.amethyst.ui.screen.AccountSessionManager import com.vitorpamplona.amethyst.ui.screen.UiSettingsState import com.vitorpamplona.amethyst.ui.tor.TorManager @@ -442,6 +444,12 @@ class AppModules( uiState } + // LRUCache should not be instanciated in the Main thread due to blocking + applicationIOScope.launch { + CachedRobohash + resourceCacheInit() + } + // registers to receive events pokeyReceiver.register(appContext) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/StringResourceCache.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/StringResourceCache.kt index 3e801e894..66330ef81 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/StringResourceCache.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/StringResourceCache.kt @@ -39,6 +39,12 @@ private var resourceCacheLanguage: String? = null // Caches most common icons in the app to avoid using disk private val iconCache = LruCache>(30) +fun resourceCacheInit() { + resourceCache + resourceCacheLanguage + iconCache +} + fun checkLanguage(currentLanguage: String) { if (resourceCacheLanguage == null) { resourceCacheLanguage = currentLanguage