Browse Source

Limit parallelism for Coil image loading

Reference: https://www.reddit.com/r/androiddev/comments/xbeizp/comment/io4ytdv/

Co-authored-by: ivaniskandar <[email protected]>
arkon 2 years ago
parent
commit
eb6ba96b57
1 changed files with 6 additions and 0 deletions
  1. 6 0
      app/src/main/java/eu/kanade/tachiyomi/App.kt

+ 6 - 0
app/src/main/java/eu/kanade/tachiyomi/App.kt

@@ -47,6 +47,7 @@ import eu.kanade.tachiyomi.util.system.isPreviewBuildType
 import eu.kanade.tachiyomi.util.system.isReleaseBuildType
 import eu.kanade.tachiyomi.util.system.logcat
 import eu.kanade.tachiyomi.util.system.notification
+import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.distinctUntilChanged
 import kotlinx.coroutines.flow.drop
 import kotlinx.coroutines.flow.launchIn
@@ -167,6 +168,11 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory {
             crossfade((300 * [email protected]).toInt())
             allowRgb565(getSystemService<ActivityManager>()!!.isLowRamDevice)
             if (networkPreferences.verboseLogging().get()) logger(DebugLogger())
+
+            // Coil spawns a new thread for every image load by default
+            fetcherDispatcher(Dispatchers.IO.limitedParallelism(8))
+            decoderDispatcher(Dispatchers.IO.limitedParallelism(2))
+            transformationDispatcher(Dispatchers.IO.limitedParallelism(2))
         }.build()
     }