Kotlin slow on GraalVM?


I just want to ask but does anyone see that Kotlin is significantly slower on GraalVM compared to on normal JDK? (Java is around 2x faster, but Kotlin is like 10-50% slower and unstable on my test).

And just another question, as GraalVM is stable now, will Jetbrains have any plans for supporting GraalVM in the near future (on Intellij and Pycharm)? It looks seriously promising. The Java speed improvement is no joke.


Considering your first question, it strongly depends on the test. The only significant difference between kotlin and java generated bytecode is the treatment of lambdas. Graal has some optimizations for java lambdas, but it won’t produce such drastic difference. So you have to present your code, otherwise, it is just speculations. I worked with kotlin and Graal and it is really fine. In some cases it is faster due to better escape analysis of generics.

As for the second question, JetBrains does not have to “support” Graal. It is just another JVM implementation and it works with kotlin-generated bytecode as it works with Java. Maybe in future, they will add some optimizations like they did for Scala though.

1 Like

For the code, it is here. I just try a simple Monty Hall problem simulation in both Java and Kotlin, and I am really surprised to see that Java is so much faster on GraalVM compared to Oracle JDK/OpenJDK, but unfortunately, Kotlin is worse (though Kotlin is lots faster on normal JDK).

And by support, what I mean is, if Jetbrains can improve the performance of Kotlin on GraalVM (if it is not just slow on my computer) and intellisense for Pycharm when importing Java libraries. Like if I import an ArrayList in Pycharm, it would be great to have autocompletion for methods like forEach, stream, add, get…

And it would be extremely interesting, if Kotlin on GraalVM can have the same Java-level interop with other languages like Python and JavaScript.

helloworld.zip (18.9 KB)

I’ve just ran your test and it has slightly better result for Kotlin than for Java on GraalVM (windows preview) and about two times better performance for Kotlin on Oracle JDK 11. The reason is that you have quite ineffective usage of streams in Java example (Kotlin filter is not based on stream API so the code is in fact quite different). Graal does optimize it while Java 11 does not. It seems that. For Kotlin we get the same performance in both environments. Either you switched the results of your tests, or you are doing something wrong.

JDK 11:

Kotlin time: 25.46
Java time: 54.48


Kotlin time: 24.96
Java time: 25.48

As for interop inside Graal. You do have it. In graal python interop implemented as a part of standard library. You can just call those functions from kotlin. The same goes in backward direction. Of course, you need kotlin code to be Java compatible for that (so not coroutines).

Hence concluded ! Kotlin is faster than Java no matter JDK11 or GraalVM

1 Like

Kotlin coroutines with loops are 18 times slower under the Graal CI fixed in GraalVM 20.1


Niiiice. Good time to update.