coil icon indicating copy to clipboard operation
coil copied to clipboard

[Coil 3] Consider replacing coil internal LruCache with androidx one

Open revonateB0T opened this issue 1 year ago • 1 comments

Now that androidx collection 1.4.0 is released and KMP ready, LruCache is stable https://developer.android.com/jetpack/androidx/releases/collection#1.4.0 https://github.com/coil-kt/coil/blob/eded350a4a1a197b61eaf5a119075ee3ec699889/coil-core/src/commonMain/kotlin/coil3/util/LruCache.kt#L7

Compose depends androidx collection anyway, so it will not introduce extra dependency.

revonateB0T avatar Mar 08 '24 17:03 revonateB0T

Nice! I didn't think they were planning to support Js/Wasm, but agreed if Compose Multiplatform uses it we should too.

colinrtwhite avatar Mar 08 '24 19:03 colinrtwhite

The only downside to this is we limit our memory cache max size to the size of signed int, which is ~2GB. This almost certainly isn't an issue for mobile apps, but it could be a limit for desktop. That said, it's likely still worth it to replace our custom implementation.

colinrtwhite avatar May 02 '24 00:05 colinrtwhite

On second thought this might not be the best idea since it locks us into a max ~2GB memory cache size as mentioned previously. This could be a real limitation for image-heavy desktop apps. androidx's LruCache also has built in synchronization and locking, which we don't need.

colinrtwhite avatar May 13 '24 18:05 colinrtwhite

It looks like androidx.collection.LruCache doesn't publish versions for JS and wasmJs either unfortunately.

Given these limitations I think it makes sense to keep Coil's custom LruCache. It's small (<100 lines) so it should be fairly easy to maintain.

colinrtwhite avatar May 13 '24 20:05 colinrtwhite