Levels of reflection in Kotlin and impact on performance


#1

Hello
It felt to me like Kotlin had levels of reflection.
At the not-so-performance-expensive level you have the basic ::class.java and .memberProperties and such.

For example, if you try to use the .annotations on a property, it keeps returning empty even if there are annotations on the field.

So does that mean if you use ::class.java and .memberProperties like above, it’s not detrimental to performance much?

Thanks


#2

There is some slight additional overhead of the kotlin reflection as additional information needs to be processed. The biggest factor of kotlin reflection is the need to include the relatively heavyweight reflection library.


#3

I understand that reflection has a performance impact in general.
What I meant is it seems there’s 2 levels to it, one with less impact and the next one with more performance degradation.

So when you can do ::.class.memberProperties, that works fine.
However, when you try to get the annotations of an individual property it doesn’t work right off the bat. It seems you have to do something more to do that.

Thanks