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

Switch to kotlinx.reflect.lite when it’s sufficient #307

Open
LouisCAD opened this issue May 15, 2017 · 12 comments
Open

Switch to kotlinx.reflect.lite when it’s sufficient #307

LouisCAD opened this issue May 15, 2017 · 12 comments
Milestone

Comments

@LouisCAD
Copy link
Contributor

Here's a lightweight version of kotlin-reflect: https://github.com/Kotlin/kotlinx.reflect.lite
My question is: Can it be used for Moshi to bring the library size down? If yes, this issue is a feature request for it.

@JakeWharton
Copy link
Collaborator

JakeWharton commented May 15, 2017 via email

@joshfriend
Copy link
Member

Currently the only supported features are names of parameters and nullability of their types.

#269 used features not currently provided by kotlinx.reflect.lite, such as getting the primary constructor and declared member properties.

@LouisCAD
Copy link
Contributor Author

Maybe you should reach to JetBrains so they include reflection features Moshi needs into kotlinx.reflect.lite?

@swankjesse
Copy link
Collaborator

Other options:

  • Dramatically shrink kotlin.reflect by changing how it uses protocol buffers
  • Switch from reflection to annotation processing

@twocity
Copy link

twocity commented Jun 12, 2017

Does moshi has any plan to support annotation processing instead of reflection?

@JakeWharton
Copy link
Collaborator

JakeWharton commented Jun 12, 2017 via email

@LouisCAD
Copy link
Contributor Author

I opened an issue in Youtrack about the gigantic size of kotlin-reflect, not ideal for Instant Apps. I requested a split, and to use Protobuf Nano (if not done already): https://youtrack.jetbrains.com/issue/KT-20793

@LouisCAD
Copy link
Contributor Author

LouisCAD commented Nov 17, 2017

It seems Room from Android Architecture Components can use Kotlin data classes without using the 1MB large (after proguarding!!) kotlin-reflect thanks to kapt generated code. Couldn't a similar technique be used in moshi?
This 1MB overhead makes it hard to build an efficient Instant App with moshi

@NightlyNexus
Copy link
Contributor

I have not used it, but https://github.com/ansman/kotshi exists. As Jake said, no current plans to support an annotation processor in this project.

@joshfriend
Copy link
Member

I think if the features listed here were implemented, use of kotlinx.reflect.lite would be possible in Moshi.

@swankjesse swankjesse added this to the Icebox milestone Jan 8, 2018
@swankjesse swankjesse changed the title Can't moshi-kotlin use kotlinx.reflect.lite instead of heavyweight kotlin-reflect? Switch to kotlinx.reflect.lite when it’s sufficient Jan 8, 2018
@ZacSweers
Copy link
Collaborator

Just an update on this for posterity: We now have a code generation artifact, and kotlinx.reflect.lite hasn't been updated in two years, though there is a PR open on it to move to kotlinx-metadata and improve the API: Kotlin/kotlinx.reflect.lite#12. We can revisit this if that PR is ever merged

@ZacSweers
Copy link
Collaborator

I've opened a PR that resolves this in spirit via replacing kotlin-reflect with kotlinx-metadata instead #1076

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