Optimize Kotlin inline class checks

This commit fixes a performance regression caused by gh-31698,
and more specifically by KClass#isValue invocations which are slow since
they load the whole module to find the class to get the descriptor.

After discussing with the Kotlin team, it has been decided that only
checking for the presence of `@JvmInline` annotation is enough for
Spring use case.

As a consequence, this commit introduces a new
KotlinDetector#isInlineClass method that performs such check, and
BeanUtils, CoroutinesUtils and WebMVC/WebFlux InvocableHandlerMethod
have been refined to leverage it.

Closes gh-32334
This commit is contained in:
Sébastien Deleuze
2024-02-28 16:38:14 +01:00
parent 5830aac1d4
commit 45c21042f6
6 changed files with 108 additions and 21 deletions

View File

@@ -319,11 +319,17 @@ public class InvocableHandlerMethod extends HandlerMethod {
case INSTANCE -> argMap.put(parameter, target);
case VALUE, EXTENSION_RECEIVER -> {
if (!parameter.isOptional() || args[index] != null) {
if (parameter.getType().getClassifier() instanceof KClass<?> kClass && kClass.isValue()) {
if (parameter.getType().getClassifier() instanceof KClass<?> kClass) {
Class<?> javaClass = JvmClassMappingKt.getJavaClass(kClass);
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(javaClass, boxImplFilter);
Assert.state(methods.length == 1, "Unable to find a single box-impl synthetic static method in " + javaClass.getName());
argMap.put(parameter, ReflectionUtils.invokeMethod(methods[0], null, args[index]));
if (KotlinDetector.isInlineClass(javaClass)) {
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(javaClass, boxImplFilter);
Assert.state(methods.length == 1,
"Unable to find a single box-impl synthetic static method in " + javaClass.getName());
argMap.put(parameter, ReflectionUtils.invokeMethod(methods[0], null, args[index]));
}
else {
argMap.put(parameter, args[index]);
}
}
else {
argMap.put(parameter, args[index]);