Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Big compilation time for Kotlin code in IntelliJ

I have used Kotlin with latest version of Eclipse for 2 months without any performance problem on my Windows 10 computer. Now I would like to do a live coding session about Kotlin with intelliJ (since it's the JetBrains language...) ultimate edition that I just installed and never used before, on a recent OSX computer. The two computers have good hardware and are no limiting my tests.

My problem is that each time there is a modification in my Kotlin code, the compilation time is between 8 seconds and 35 seconds. I did my tests on minimalist code:

class TestKotlin {
    var a = 1
}

If I change the variable "a" and so need to build again, it always need 8 seconds in the best cases to complete the compilation.

Since I want to do a live coding session with a lot of small functions and compilations, this kind of delay is way too much significative. The viewers will need to wait a lot before to see the results at each compilation, they are logically expecting good performance from IntelliJ tool.

In the same project, I tried to do the same kind of Java class (with a single attribute) and modify its attribute in order to trigger the compilation, and it takes less than 1 second to compile.

I tried to manually compile the code in command line with that:

kotlinc hello.kt -include-runtime -d hello.jar
java -jar hello.jar

I had some decent compilation times, even if it was near to 3 seconds.

When I look at the "Messages" screen in IntelliJ while it is compiling Kotlin code, I can see this:

Information:Kotlin: Kotlin JPS plugin version 1.0.6-release-127
Information:Kotlin: Using kotlin-home = /Users/myUsername/Library/Application Support/IntelliJIdea2016.3/Kotlin/kotlinc

It stops here for all the compilation time, and then do almost instantaneously the next steps:

Information:Kotlin: Kotlin Compiler version 1.0.6-release-127
Information:17/01/17 11:38 - Compilation completed successfully in 11s 639ms

Maybe there is a problem in the configuration of IntelliJ or something like this. I had a hard time at searching for something that could improve the performances but nothing helped me...

I would be very grateful if someone can help me to have some realistic compilation time with Kotlin in Intellij like in Eclipse!

like image 574
Bastien7 Avatar asked Jan 17 '17 12:01

Bastien7


People also ask

Does Kotlin compile faster than Java?

Since Gradle is the default for Kotlin, and with its daemon running and incremental compilation turned on, the clash between Kotlin vs Java performance, Kotlin compiles as fast or slightly faster than Java.

How do I compile Kotlin in IntelliJ?

Common settingsSelect the version of the Kotlin compiler that is used to run both local and CI builds. Select the version of Kotlin used by the compiler. Select the API version used by the Kotlin compiler. Specify the command-line parameters and options to be passed to the compiler at its start.


1 Answers

This seems similar to the problem KT-15491.

To ensure that it's your case too, try to execute the following simple Kotlin program:

import java.io.File
import kotlin.system.measureNanoTime

fun main(args: Array<String>) {
    val elapsedNs = measureNanoTime { File.createTempFile("tmp", "", null).deleteOnExit() }
    println(elapsedNs.toDouble() / 1000000000)
}

If the printed elapsed time is significantly greater than a fraction of a second, than that is the reason.

This issue affects not only Kotlin compiler but every JVM program that tries to create a temporary file, or to do any other action involving SecureRandom class.

I've experienced the same slowdown on each JPS build on my Windows 7 notebook. I've tried the workaround with security providers order described in this question and it helped.

like image 119
Ilya Avatar answered Oct 15 '22 17:10

Ilya