Open jreznot opened 1 year ago
I would recommend noinline for lambdas, we cannot eliminate them fully anyway, as UniversalMarshaller
needs to store some instances:
inline fun <reified T : Any> create(noinline reader: (AbstractBuffer) -> T,
noinline writer: (AbstractBuffer, T) -> Unit,
predefinedId: Int? = null): UniversalMarshaller<T> {
return UniversalMarshaller(T::class, { _, stream -> reader(stream) }, { _, stream, v -> writer(stream, v) }, predefinedId)
}
A proposed solution that should work in Kotlin 1.9 (currently, it generates exactly the same number of classes):
inline fun <reified T : Any> create(
noinline reader: (AbstractBuffer) -> T,
noinline writer: (AbstractBuffer, T) -> Unit,
predefinedId: Int? = null
): UniversalMarshaller<T> {
return create(T::class, reader, writer, predefinedId)
}
/**
* This is a non-inline companion of the above function, to avoid creating too many class files for crossinline
* lambdas.
*/
fun <T : Any> create(
kClass: KClass<T>,
reader: (AbstractBuffer) -> T,
writer: (AbstractBuffer, T) -> Unit,
predefinedId: Int? = null
): UniversalMarshaller<T> {
return UniversalMarshaller(
kClass,
{ _, stream -> reader(stream) },
{ _, stream, v -> writer(stream, v) },
predefinedId
)
}
So, to fix this issue, we'll have to wait for Kotlin 1.9 with extended invokedynamic
usage.
We will be waiting.
Check this:
This means that for every callsite of FrameworkMarshallers.create there will be separate class created. Our JVM classloading logs for IntelliJ IDA shows clearly: