kotlin reflection on the jvm seems to be 100x slower than java reflection for some usecases. is that a known issue?
christophsturm
03/26/2021, 11:39 AM
people say reflection is slow, but things that take <1ms in java take 300ms on kotlin reflection
christophsturm
03/26/2021, 11:40 AM
KClassImpl has an inner class
Data
and this class takes ages to build. and it is built lazily before any other reflection call is possible
christophsturm
03/26/2021, 11:41 AM
1ms:
Copy code
val instanceField = jClass.getDeclaredField("INSTANCE")
val obj = instanceField.get(null)
val contexts = jClass.getDeclaredMethod("getContext").invoke(obj)
300ms:
Copy code
return kClass.declaredMemberProperties.single { it.name == "context"
}.call(kClass.objectInstance) as RootContext