-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
Can't create handler inside thread that has not called Looper.prepare() #295
Comments
Is it initializing the OkHttpClient that takes time, or the call to get()? Do you have a sample app that reproduces the problem or a trace? I'll look in to whether registering off the main thread is/should be safe. |
Here is an example how to reproduce the problem https://gist.github.com/stepango/52e9c69186317af1e95b |
Sorry by problem I meant the 30ms delay, not the exception. Registering factories should be fast enough that a background thread isn't needed. |
Indeed, but the main problem is that many other libraries also should be initialised in the main thread so for big projects it dramatically increase app start time. Second problem here that on devices older that Nexus 5 it will be longer than 30ms. Unfortunately, I don't have any benchmarks for now. |
Branched the 30ms issue into #298, I'd imagine that strict mode violation is the reason for the delay. |
@sjudd I did a microbenchmark on my Samsung Galaxy S4 4.4.2: @Override public void Application.onCreate() {
Log.v("TRACE", "NOW"); ConcurrentTools.ignorantSleep(10000);
long time1 = System.nanoTime(); Glide glide = Glide.get(this);
long time2 = System.nanoTime(); OkHttpClient client = new OkHttpClient();
long time3 = System.nanoTime(); Factory factory = new Factory(client);
long time4 = System.nanoTime(); glide.register(GlideUrl.class, InputStream.class, factory);
long time5 = System.nanoTime();
Log.v("TRACE", "STOP"); ConcurrentTools.ignorantSleep(10000);
Log.v("TIMING", String.format(Locale.ROOT, "Glide.get: %.2f, Glide.register: %.2f, new Client: %.2f, new Factory: %.2f",
diff(time1, time2), diff(time4, time5), diff(time2, time3), diff(time3, time4)));
}
private float diff(long time1, long time2) { return (time2 - time1) / 1000000f; } ... and the result is:
From the method trace: Glide.get is 92% of |
Hmm I wonder if it's different on L. It's also possible the strict mode logging isn't particularly accurate. I added the actual stack trace to the other issue and opened #299 to track the Glide.get() timing. |
Glide init with following code takes ~30ms on nexus 5/Android 5.0.1
I tried to init glide in background thread but get a following error
The text was updated successfully, but these errors were encountered: