<@UBTGMFRCZ> I noticed that while using Coil in la...
# compose
s
@cb I noticed that while using Coil in lazy list to load images if i use drawable instead of url then the performance is quite laggy . Is it loading image from url in background thread and from drawable resource in main thread???
s
How are you loading local images from resources with Coil? Shouldn't that just be an
Image(painterResource(resourceId))
and not bother with Coil at all?
s
Coil can handle both local as well as remote images. Well i could use Image composable but i did not in my case and i just wanted to confirm above case
s
Ahh, sorry, I was thinking you were passing in a
Painter
to `Coil()`/`rememberCoilPainter()` , in which case
Image()
should be used, but it seems passing resource IDs directly is still supported. My bad. simple smile
s
No worries. Since i was using Coil library i just used it instead of Image composable.
c
Are you passing in a drawable id? Coil is responsible for all of the loading side of things, so I’m not sure if it’s done on the main thread or not.
If you’re loading a bitmap from resources, make sure it’s in
drawable-nodpi
or
raw
, otherwise it will be density-scaled, then potentially scaled to the size of the
Image
which would slow things down
Also, make sure to upgrade to 0.8.1 if you haven't done so yet
s
Ok thanks will do
c
@cb Isn't it possible to use
<http://Dispatchers.IO|Dispatchers.IO>
to load here?
c
Yes it is possible, but we won't be doing it. It's up to the loading library to handle background work as appropriate. For instance, Glide doesn't use Coroutines at all and performs it's own thread handling. Switching to
<http://Dispatchers.IO|Dispatchers.IO>
isn't going to do much there. You can customize Coil's
ImageLoader
as you see fit, including the dispatcher it uses.
2