I'm running the following code and it's taking between 3 and 6 seconds to execute on both OSX (Sierra) and Windows 10. I've never seen such slowness using JSR-223, especially considering the simplicity of what's being evaluated. Digging through the call tree in YourKit it seems to be spending most of this time in KotlinJsr223JvmLocalScriptEngine.getReplEvaluator, but I can't see past that.
This is using jdk1.8.0_71 and kotlin 1.2.10.
Any ideas?
Thanks
import javax.script.ScriptEngineManager
fun main(args: Array<String>) {
System.setProperty("idea.io.use.fallback", "true") // need this on windows, not required on osx it seems!
val engine = ScriptEngineManager().getEngineByExtension("kts")!!
val startTime = System.currentTimeMillis()
engine.eval("val x = 5")
println(System.currentTimeMillis() - startTime)
}
My build script is as follows:
buildscript {
ext.kotlin_version = '1.2.10'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
group 'xxx'
version '1.0-SNAPSHOT'
apply plugin: 'kotlin'
repositories {
mavenCentral()
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-script-util:$kotlin_version"
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}