-
Notifications
You must be signed in to change notification settings - Fork 624
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
Serializing object
classes is 10x slower than data classes
#2003
Comments
The problem has multiple layers in it. First of all, intrinsics are not yet implemented (#1348), which is our biggest issue right now. I suggest reading through the issue to understand why it's important. The second problem is that we have seemingly the same code having a significant difference in its performance characteristics. All lookups in all benchmarks use reflection under the hood and use basically the same code path (more or less). Though, it shouldn't be ten times faster. I've ran my own benchmarks under the profiler and pin-pointed the root cause: kotlinx.serialization/core/jvmMain/src/kotlinx/serialization/internal/Platform.kt Lines 104 to 115 in 16a85df
The problem here is simple -- we either have to use Or, we can use Java API won't let us do any better here, so this is a tradeoff we are willing to accept. Hopefully, proper intrinsics (#1348) will make all these problems disappear, so closing as "won't fix" |
Yup, makes total sense at the library level. Thanks for attaching the flame graph. Very interesting! For now, we're going to workaround this by checking for |
Thanks for reporting! This report got #2004 rolling as well as our work on speeding up some [obvious] kotlin-reflect parts |
NB: You can also use generated |
I've tweaked reflection here and there (https://youtrack.jetbrains.com/issue/KT-50705/Use-ClassValue-to-cache-KClass-objects-in-kotlin-reflect and subtasks) and now there is no Kotlin-specific reflection whatsoever. The changes are targeting 1.8.0 release. Along with #2004 (@shanshin works on that right now), we expect the difference between reified and |
Copying over my Android Microbenchmarks results (ran on Google Pixel 3):
Also interesting is that the intrinsic is usually (marginally) slower than using reflection.
To Reproduce
All benchmarks are here: https://github.com/chrisbanes/kotlin-serialization-object-perf
Expected behavior
I'd expect objects to be faster than data classes (or at least similar).
Environment
The text was updated successfully, but these errors were encountered: