12

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!

Bastien7
  • 250
  • 3
  • 7
  • I'm voting to close this question as off-topic because there isn't a 'this question is old, and the tools no longer have this issue' option anywhere. @OP are you still experiencing this issue? With the improvements in the Kotlin plugin, I would be very surprised if you are. – Mikezx6r Sep 29 '17 at 12:27
  • @Mikezx6r kotlin compilation is still super slow for me as of kotlin 1.3.10. In general, intellij and speed have always been an issue for me. Multi second compile times on a one line change basically means that incremental compilation is not really working incrementally. – Jilles van Gurp Nov 27 '18 at 17:00
  • Can you create a sample project and put somewhere public. I can then check it out, and report/see times on my machine. Maybe I've just never noticed the delay because I'm not trying to do live coding demos. An alternative for a demo would be a scratch file. Depending on what you're demoing, that works quite well, and quickly. – Mikezx6r Nov 29 '18 at 03:18

2 Answers2

1

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.

Community
  • 1
  • 1
Ilya
  • 21,871
  • 8
  • 73
  • 92
  • It seems to not be my case: this program prints less than 0.03 seconds on my OSX computer... :( I tried to compile/run all kind of Kotlin program with Eclipse and I have very very small compilation time (but not as good as IntelliJ for Kotlin...) – Bastien7 Jan 17 '17 at 18:54
  • @Bastien7 Take a look at these questions then: http://stackoverflow.com/questions/39636792/jvm-takes-a-long-time-to-resolve-ip-address-for-localhost and http://stackoverflow.com/questions/33289695/inetaddress-getlocalhost-slow-to-run-30-seconds/33289897 – Ilya Apr 21 '17 at 19:44
  • 1
    Yes you're right, there are issues about it on YouTrack now, and the Idea team first said us to fix the OSX problem by ourself. But since we are many to have asked them a solution they planned to apply a JDK patch : https://youtrack.jetbrains.com/issue/KT-17523#comment=27-2118243 – Bastien7 Apr 25 '17 at 13:41
  • Hi, I think I'm experiencing the same IDE lag/slowness issue in Kotlin projects, https://stackoverflow.com/questions/45581424/extremely-slow-in-autocompletion-code-analysis-for-kotlin-projects-in-intellij. Did you end up finding a fix for it? Please let me know. Thanks. – Kelvin Aug 09 '17 at 04:47
0

Make sure you have checked those boxes in settings:

  • Incremental Kotlin compilation
  • Kotlin compiler daemon (keeps the kotlinc process alive)
voddan
  • 31,956
  • 8
  • 77
  • 87
  • 3
    "Keep compiler process alive between invocations" and "Enable precise incremental compilation" are already checked in my preferences. – Bastien7 Jan 17 '17 at 12:30
  • Search for them in general settings – voddan Jan 18 '17 at 11:46
  • Hi, I think I'm experiencing the same IDE lag/slowness issue in Kotlin projects, https://stackoverflow.com/questions/45581424/extremely-slow-in-autocompletion-code-analysis-for-kotlin-projects-in-intellij. Did you end up finding a fix for it? Please let me know. Thanks. – Kelvin Aug 09 '17 at 04:48