-
Notifications
You must be signed in to change notification settings - Fork 669
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Asynchronous initialization of ImageLoader #2097
Comments
It looks like you were initializing your
For docs, I'd be open to a PR that improves this! |
I ran a quick benchmark on a Pixel 7 emulator and an val iterations = 1_000
var sum = 0L
var imageLoader: ImageLoader?
repeat(iterations) {
sum += measureNanoTime {
imageLoader = ImageLoader(context)
}
imageLoader?.shutdown()
}
println("BENCHMARK OUTPUT: ${sum / iterations.toDouble()}") |
There's a couple of problems measuring the timing this way:
What I did to benchmak this, was using Macrobenchmark in the real app with For 10 iterations, I see these results
I further started digging into what's happening and I think I know now. I followed you advice to only have When the first image is shown on screen (in NIA it's the The cause are (my hypothesis) the I think Coil should be able to register the system services on a |
When I set |
Ah thanks for digging in! Agreed - |
Fixed here in the 3.x release. I'll also backport the change to the next release, I tried running my own macrobenchmark test after the changes, but the initialization method didn't appear in the measured methods. |
Awesome! Thanks! 🎉 If you'd like to help diagnose the macrobenchmark tests, maybe ping me on ASG? |
As discussed in coil-kt/coil#2097 the problem is caused by regitering system services, which will be fixed in 2.6.0 Change-Id: I9085309780508137f10b25ff82deed3c62e5d159
As discussed in coil-kt/coil#2097 the problem is caused by regitering system services, which will be fixed in 2.6.0 Change-Id: I9085309780508137f10b25ff82deed3c62e5d159
As discussed in coil-kt/coil#2097 the problem is caused by regitering system services, which will be fixed in 2.6.0 Change-Id: I9085309780508137f10b25ff82deed3c62e5d159
PR for a cautionary fix on OkHttp 5.x |
As discussed in coil-kt/coil#2097 the problem is caused by regitering system services, which will be fixed in 2.6.0 Change-Id: I9085309780508137f10b25ff82deed3c62e5d159
Is your feature request related to a problem? Please describe.
In Now in Android we had the
Application
implementImageLoaderFactory
and initialize theImageLoader
with thenewImageLoader()
method.We realised that the initialization happens on the main thread with the composition of the first image on screen, which causes some frames to be skipped (~15ms on Pixel 6 in
benchmark
build).What we did was to start initialization of Coil on a background thread and in case it'd take too long, block the first image to wait for the initialization (android/nowinandroid#1190).
Describe the solution you'd like
I think it's not 100% obvious that Coil will initialize on the main thread and given it's initializing OkHttp, it may take significant time to do so.
a) Could there be a similar way baked-in to Coil to do initialization in a non-blocking way?
b) Should this be documented in the documentation so that people are aware this might happen?
c) ?
Additional context
The text was updated successfully, but these errors were encountered: