Bastien7
Bastien7

Reputation: 250

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!

Upvotes: 12

Views: 4878

Answers (2)

Ilya
Ilya

Reputation: 23154

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.

Upvotes: 1

voddan
voddan

Reputation: 33829

Make sure you have checked those boxes in settings:

  • Incremental Kotlin compilation
  • Kotlin compiler daemon (keeps the kotlinc process alive)

Upvotes: 0

Related Questions