Kotlin compile so slowly


#1

Since my team start use kotlin as android develop language last year, we find that compiling app spent more and more time as the percent of kotlin code increasing. Though I do not spent time to compare with java exactly, but we can feel it obviously.


#2

Faster compilation compared to Scala was one of the design goals of Kotlin. I wonder how fast the compiler actually is. Is the a benchmark comparing the compilers of Java, Scala and Kotlin? Would be very interesting.


#3

It’s pretty fast but surely the issue here is the lack of incremental compilation in Gradle rather than the speed of the compiler itself?


#4

Still a benchmark done by JetBrains themselves would be nice. Compilation time of Java/Kotlin/Scala of similar code…


#5

My own experience: it’s slow as molasses compared to Java compilation. We’re talking 5-10 seconds to compiler less than 10k loc. But I use inlining heavily, so that might be a factor.


#6

I will provide some data to prove Kotlin compile slowly.
My build enviroment:

Gradle 2.11 
Kotlin 1.0.3
compileSdkVersion 23
buildToolsVersion 23.0.3

In my project, there are 130 Kotlin files and 607 Java files. When i build my project with clean, with the output of build info.

  50658ms   :normandy:compileHujiangMisKotlin
  5233ms   :normandy:compileHujiangMisJavaWithJavac

Is this enough to prove Kotlin compile slowly?


#7

Make sure you have incremental compilation enabled


#8

Please mind my situation : build my project with clean.


#9

Yes, that seems pretty definitive proof that you are hitting a bad performance problem. No clue what it might be though.


#10

Do other people using Kotlin encounter similar compile times or is this a special case? compileHujiangMisKotlin / compileHujiangMisJavaWithJavac is roughly factor 10 and 607 / 130 is about factor 4.5.


#11

I am not sure, the context of having so much Java and Kotlin code is not common. There is not so much people start use Kotlin to develop around me, most of people just try it on.

Do not you troubled by this case?


#12

Here is an interesting real world comparison of Java and Kotlin compiler speed.

TLDR: In the worst case scenarios Kotlin compiles about 15 % slower than Java and in typical use cases slightly faster than Java.


#13

Well done measurements. Thanks a lot. Now I feel good again ;-).


#14

I am seeing this, and it’s not a case that incremental compilation is useful - for test driven development. I need to be able to compile my test classes over and over and see that they are failing/passing. But the Kotlin compiler takes 10-12 seconds for even the most basic cases, whereas the Java compiler can turn the tests around in 2-3 seconds. That difference is an absolute productivity killer, and has me considering writing my tests only in Java. Very unfortunate, especially given that Jetbrains just pushed out a video on TDD that used Kotlin.


#15

Still hitting that problem?
See: https://youtrack.jetbrains.com/issue/KT-17523


#16

I have the same issue, the compilation slew down roughly 10x since we migrated to Kotlin.


#17

Over 22000 lines kotlin here, with a smaller amount (but at least 10000 I think) of Java taken from OSS Android libraries for modification. The kaptDebugKotlin and compileDebugKotlin tasks are AWFULly slow, a clean build takes more than 3 minutes. I am using data binding, DBFlow and Parceler, all of which generate code – I regret using DBFlow and Parceler now, because my annotating processing takes so long.

I’d be happy to send over my entire project to JB but the kotlin would have to be obfuscated.


#18

Not exactly the answer to those grievances, but I found that JRebel plugin (which is now free for Android) helps to alleviate the long compilation a lot in everyday use.


#19

kaptDebugKotlin tasks are very slow when using Parceler. And it looks like they don’t really support incremental compilation.