-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
Slow creating new instance of OkHttpClient() #4337
Comments
Can you show a stacktrace of this? I believe you, but good to discuss with a specific code path. Ultimately the cost of JVM SSL init + OkHttp init is either on creating first client, or first request. Both have drawbacks, e.g. in some cases apps can be doing startup with a loading screen, but then first request is faster which may be better for users. |
Here is trace file https://www.dropbox.com/s/50eupuup8bplks8/okhttp.zip?dl=1 |
I think there is an easy win here. Use a HashMap, change the static fields from a normal lookup to an (assumed to be unique) insert. Then on lookup, check the happy path first, and on failure, do a secondary lookup s/TLS_/SSL_/ or s/SSL_/TLS_/. @swankjesse thoughts? |
On a desktop mac, roughly representation numbers Before: Init Took 2.373407ms |
@tprochazka What device did you profile on? |
This is still a tiny amount of time relative to the first actual use of the native TLS library, which is roughly 100x more expensive and happens on first request. |
The Trace is from Samsung S8+ |
@yschimke thumbs up on making things faster! |
Creating a new instance of OkHttpClient is very slow because initializing HTTPS support probably. It spends more than 500ms in CipherSuite class. I understand that it is probably important, but why it happens directly when a new instance is created and not during first HTTP request which happens every time on a background thread. It is very unusual, to do such time complex operation directly after the instance is created.
The text was updated successfully, but these errors were encountered: