square / okhttp

Square’s meticulous HTTP client for the JVM, Android, and GraalVM.
https://square.github.io/okhttp/
Apache License 2.0
45.71k stars 9.15k forks source link

Should SSLContext construction be deferred during OkHttpClient construction #8231

Open yschimke opened 7 months ago

yschimke commented 7 months ago

https://www.zacsweers.dev/dagger-party-tricks-deferred-okhttp-init/

OkHttpClient initialization can take upwards of 100ms on some Android devices in the wild due to its use of TrustManagerFactory. Initializing the Cache is also not free, as it creates an internal Executor and may incur some disk IO if you want to prepare a cache directory for it first.

swankjesse commented 5 months ago

Is the best solution to make OkHttp lazy internally? Or to encourage our users to instantiate their OkHttp clients lazily? I think making OkHttp lazy potentially introduces other problems by deferring failures

yschimke commented 5 months ago

I'm not sure. But it's

A) a real problem B) the default behaviour and common. C) something we put on every developer to do if we don't.