-
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
API to get serializer for a class without creating kotlin reflection class #1819
Comments
using java class only:
|
…efection wrapper creation Kotlin/kotlinx.serialization#1819 GitOrigin-RevId: 9a1bce7a70b6c68c9c6267baa53ac0509b9ff294
Could you please share a small example of the overhead for us to have something we can compare? It seems like we indeed can provide a delicate API that operates with a regular |
For years already in IJ Platform, we do not create kotlin reflection class wrappers if we can avoid it. Profiler snapshot provided above. We have hundreds of persistence state components. That's also not only about performance, but about avoiding extra caches and so on (dynamic plugin reloading, for example). Say, because it is visible in a profiler snapshot, then another core team member will ask me again and again about that on some performance and/or memory issues investigation. Fewer issues, easier for me to promote kotlin. |
I'm not a developer of the IJ platform and not aware of your internal guidelines and constraints, thus I've been asking for additional details.
There may be a lot of reasons why this call appeared in the snapshot. For example, it's the very first call to Kotlin reflection and thus it's loading all the classes.
Are you talking about the cache in Kotlin reflection itself (one in Are you interested in a "cold" performance (e.g. one-shot invocation) or a "hot" one (when JIT kicks in)? |
It may be a reason. We are working on speeding up the start-up. Every used API is checked and profiled. If we can avoid using something and it is worth it, we do avoid it.
Yes, I mean potential not clear side-effects of used 3rd-party API.
Cold :( For example, running tests, application start-up.
We have very different people in a core team ;) In short — often easier to avoid questionable code than to explain and check again and again that this piece of code is innocent and doesn't bring any issues. The first question is always — can we avoid it at all? If we cannot, then the second question — is it acceptable or not? Here no need to think about "is 10% ok or not", because it is clear that kotlin reflection wrapper is not needed here at all.
Only by mistake or if we cannot avoid it. For example, in some cases we have to use a special shim in Java to avoid it (https://github.com/JetBrains/intellij-community/blob/master/platform/object-serializer/src/PropertyAnnotationUtil.java) |
…uctSerializerForGivenTypeArgs Prerequisite for #1819
I've investigated potential solutions for the problem. In general, it seems to be working as intended with the only exception -- if the target class is marked with Also, I've studied implementation from JetBrains/intellij-community@51be4e7 -- it seems to be incomplete. E.g. it won't work for enums, primitive types, classes with named companions*, classes with generic parameters and arrays.
|
Not required for our use case.
For now, we do not use kotlinx serialization for these types. I do understand, that you probably don't want to open API, that will support only regular classes (it is currently internal in your implementation) — to reduce API surface and simplify it. I don't bother about performance loss on such checks, I guess it is negligible. |
Let me rephrase it directly: consider we have an API |
Yes, such an API will be useful for me and it will be used as is (and |
…lass.serializerOrNull(), but attempts not to instantiate KClass when possible Fixes #1819
I'm a bit late here, but what's wrong with the
|
|
In the new release,it should be enough to use |
What is your use-case and why do you need this feature?
Current experimental API
::kotlin.get().serializer()
implies creating extra kotlin reflection class. That's not acceptable from a performance point of view in all cases.Describe the solution you'd like
Could you please provide API to use just a java
Class
?The text was updated successfully, but these errors were encountered: