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

Optimize Kotlin reflection runtime efficiency #21546

Open
spring-projects-issues opened this issue Jul 4, 2018 · 3 comments
Open

Optimize Kotlin reflection runtime efficiency #21546

spring-projects-issues opened this issue Jul 4, 2018 · 3 comments
Assignees
Labels
in: kotlin type: enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Jul 4, 2018

kotlin-reflect is a big 2 MB JAR, producing important CPU and memory spikes at startup on the JVM.

It would be interesting to explore if it could be replaced by a lighter incarnation like https://github.com/Kotlin/kotlinx.reflect.lite or use kotlinx-metadata-jvm at build time to generate some kind of reflection index. jackson-module-kotlin should also work with similar approach (not blocking now that we have Kotlin Serialization support).

@sdeleuze
Copy link
Contributor

@sdeleuze sdeleuze commented Jan 28, 2021

Short term kotlin-reflect usage could be optimized, especially for native use case, by KT-44594 so feel free to vote for it on Kotlin issue tracker.

sdeleuze added a commit to spring-projects-experimental/spring-native that referenced this issue Feb 24, 2021
Kotlin Coroutines are now supported but require additional
reflection entries due to how Coroutines generates bytecode
with an `Object` return type, see
spring-projects/spring-framework#21546
for a potential future fix.

Closes gh-409
@sdeleuze sdeleuze changed the title Use kotlinx-metadata-jvm at build time instead of kotlin-reflect at runtime Optimize Kotlin reflection runtime efficiency Oct 28, 2021
@sdeleuze
Copy link
Contributor

@sdeleuze sdeleuze commented Oct 28, 2021

After a deeper look, I am not sure kotlinx-metadata-jvm is suitable for our use case since it would require an alternative reflection metadata index. Also kotlin-reflect is conceptually ok for native since it is using Java reflection (which can be quite cheap for some use cases with GraalVM 21.3+) and not class resources (not available on native at runtime).

So my hope for the future is that we could collaborate with Kotlin team (cc @udalov @elizarov) to have a more optimized version of kotlin-reflect.jar. I does not have to be the full beast, maybe a lighter implementation of a subset (we only use a very small subset of it, see https://github.com/spring-projects/spring-framework/search?q=ReflectJvmMapping) inspired from https://github.com/Kotlin/kotlinx.reflect.lite. Notice that should use regular reflection not *.class resources because those are not available on native.

Could be useful for Jackson Kotlin support as well.

That would be a good fit with Spring Framework 6.

@sdeleuze
Copy link
Contributor

@sdeleuze sdeleuze commented Oct 29, 2021

@jhoeller jhoeller removed this from the 5.x milestone Nov 1, 2021
@jhoeller jhoeller added this to the 6.0.x milestone Nov 1, 2021
@sdeleuze sdeleuze added in: kotlin and removed theme: native in: core labels Jan 19, 2022
@poutsma poutsma self-assigned this May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: kotlin type: enhancement
Projects
None yet
Development

No branches or pull requests

4 participants