Skip to content
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

okhttp,interop-testing: use forked OkHttp classes #3325

Closed

Conversation

ericgribkoff
Copy link
Contributor

@ericgribkoff ericgribkoff commented Aug 8, 2017

This reduces our dependency on the OkHttp 2.5.0 library by switching imports of three classes (CipherSuite, ConnectionSpec, and TlsVersion) from com.squareup.okhttp.* to our already manually copied/forked classes in io.grpc.okhttp.internal.*.

For our Android Hello World app after Proguard, this change reduces the classes.dex size of our com.squareup.okhttp.* dependencies from 12.3KB to 4.0KB, and a modest reduction in APK size of 4.3KB (from 710.8KB to 706.5KB).

The following classes are still direct dependencies of OkHttpClientTransport:

  • com.squareup.okhttp.Credentials
  • com.squareup.okhttp.HttpUrl
  • com.squareup.okhttp.Request
  • com.squareup.okhttp.internal.http.StatusLine

None of these are forked in io.grpc.okhttp.internal, although StatusLine brings in com.squareup.okhttp.Protocol, which is already forked as io.grpc.okhttp.internal.Protocol. We could save an additional 400B out of the 4KB of the com.squareup.okhttp.* dependencies by forking StatusLine (and forking its dependency com.squareup.okhttp.Response).

I manually downloaded the OkHttp 2.5.0 jar and verified that the implementations of CipherSuite, ConnectionSpec, and TlsVersion match our own forked copies (we do have one method with increased visibility in our copy of ConnectionSpec).

@@ -37,7 +34,10 @@
import io.grpc.internal.KeepAliveManager;
import io.grpc.internal.SharedResourceHolder;
import io.grpc.internal.SharedResourceHolder.Resource;
import io.grpc.okhttp.internal.CipherSuite;
import io.grpc.okhttp.internal.ConnectionSpec;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ConnectionSpec is part of grpc's API in this class. We don't want to expose our internal fork, so we let users specify okhttp's ConnectionSpec and then we use Utils.convertSpec() to copy it into an internal equivalent.

Feel free to eagerly convert in connectionSpec(); that would allow proguard to remove the references if it isn't specified.

@ericgribkoff
Copy link
Contributor Author

Superseded by #4267

@ericgribkoff ericgribkoff deleted the use_copied_okhttp_dependencies branch March 26, 2018 16:33
@lock lock bot locked as resolved and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants