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

Kotlin IR for speed and profit #3707

Closed
justintuchek opened this issue Mar 9, 2022 · 0 comments
Closed

Kotlin IR for speed and profit #3707

justintuchek opened this issue Mar 9, 2022 · 0 comments

Comments

@justintuchek
Copy link

justintuchek commented Mar 9, 2022

Reading through Moshi IR sparked a few ideas on how a compiler plugin and/or Kotlin IR could be beneficial to Retrofit

  1. Eliminating Proxy.newProxyInstance(...)

    Given an Retrofit compatible interface such as

     public interface GitHubService {
       @GET("users/{user}/repos")
       suspend fun listRepos(@Path("user") String user): Response<List<repos>>
     }

    It seems possible that we could generate something like RetrofitGenerated_GitHubService.class class during compilation time

    Retrofit.create(final Class<T> service) would use the given interface as a key to do a lookup for the generated implementation - either something like Class.forName(...) or collecting them while they're being generated

    The Retrofit instance used to create the class instance would be provided to the generated class so it has access to required Call.Factory, Converter.Factory, CallAdapter.Factory, etc to facilitate the call that currently happen within HttpServiceMethod

  2. Move all interface validation to compile time errors

    Since RetrofitGenerated_* classes would be built at compile time we would be aware of any standard declaration issues

    I believe it would be possible for this to work for custom CallAdapter implementations as well if we were able to walk the methods of a given interface and check those against the provided CallAdapter.Factory list

  3. A path towards Multiplatform support?

    This isn't a leading point of this issue due to comments here Multiplatform support #3181 (comment) - to be honest I haven't kept up with Okio/OkHttp's Multiplatform capabilities to know if this is even worth pursuing here

    With Moshi IR people may eventually have a meaningful choice beyond just KotinX.Serialization. I recognize that there's a ton of other work to do here as well


This really came to mind while thinking about reducing application startup time where we can certainly move our interface creation but not eliminate it

I wouldn't be envious of the maintenance for both Proxy creation and a compiler plugin. If this isn't a path worth pursuing feel free to close this issue

Figured this high level issue was worth feeling out before over-investing in a PR or some offshoot prototype

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant