CLI: Change kotlin reflection to java reflection

The command line argument parser is using between 0.25s and 0.5s
(depending on platform) on finding annotated properties. This fix
replaces the slow kotlin reflection with java reflection, which is an
order of magnitude faster.

 #KT-58183 Fixed
This commit is contained in:
Troels Bjerre Lund
2023-04-29 07:55:23 +02:00
committed by Space Team
parent b28b0e70b6
commit 111bb461a9
12 changed files with 61 additions and 43 deletions
@@ -28,7 +28,7 @@ import org.jetbrains.kotlin.gradle.util.assertNotNull
import org.jetbrains.kotlin.gradle.util.buildProjectWithJvm
import org.jetbrains.kotlin.gradle.util.buildProjectWithMPP
import org.jetbrains.kotlin.gradle.util.main
import kotlin.reflect.full.findAnnotation
import kotlin.reflect.jvm.javaField
import kotlin.test.*
@@ -78,7 +78,7 @@ class KotlinCompileArgumentsTest {
val arguments = mainCompilationTask.createCompilerArguments(lenient)
val argumentsString = ArgumentUtils.convertArgumentsToStringList(arguments)
val jvmTargetArgument = K2JVMCompilerArguments::jvmTarget.findAnnotation<Argument>()!!.value
val jvmTargetArgument = K2JVMCompilerArguments::jvmTarget.javaField!!.getAnnotation(Argument::class.java)!!.value
if (jvmTargetArgument !in argumentsString) fail("Missing '$jvmTargetArgument' in argument list")
val indexOfJvmTargetArgument = argumentsString.indexOf(jvmTargetArgument)
val jvmTargetTargetArgumentValue = argumentsString.getOrNull(indexOfJvmTargetArgument + 1)
@@ -158,4 +158,4 @@ class KotlinCompileArgumentsTest {
compileTask.createCompilerArguments(lenient).fragmentSources.orEmpty().toSet()
)
}
}
}