square / moshi

A modern JSON library for Kotlin and Java.
https://square.github.io/moshi/1.x/
Apache License 2.0
9.77k stars 760 forks source link

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

Open LouisCAD opened 7 years ago

LouisCAD commented 7 years ago

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 commented 7 years ago

From what I remember, no, but that was back when it was first introduced. We should look again.

On Mon, May 15, 2017 at 12:47 PM Louis CAD notifications@github.com wrote:

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.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/square/moshi/issues/307, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEagcpXw6-O0zwYhNGINdyS74AyS1ks5r6KvUgaJpZM4NbmkG .

joshfriend commented 7 years ago

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 commented 7 years ago

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

swankjesse commented 7 years ago

Other options:

twocity commented 7 years ago

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

JakeWharton commented 7 years ago

No plans. Try auto-value-moshi.

On Mon, Jun 12, 2017 at 3:00 AM twocity notifications@github.com wrote:

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

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/square/moshi/issues/307#issuecomment-307706132, or mute the thread https://github.com/notifications/unsubscribe-auth/AAEEEf57aHJjJgDVFYT5xYhflFA78frNks5sDOIfgaJpZM4NbmkG .

LouisCAD commented 7 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

ZacSweers commented 5 years ago

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: https://github.com/Kotlin/kotlinx.reflect.lite/pull/12. We can revisit this if that PR is ever merged

ZacSweers commented 4 years ago

I've opened a PR that resolves this in spirit via replacing kotlin-reflect with kotlinx-metadata instead https://github.com/square/moshi/pull/1076