Tools

Gradle Daemon Support for Faster Compilation

We are currently working on improving compilation times. Today we are happy to invite you to try Kotlin 0.12.1230 making use of the Gradle Daemon. It eliminates startup costs, and your builds run faster.

Background

Among other things, loading classes of the compiler and warmup activities of the JVM seem to contribute a lot to the time it takes kotlinc to run. This is why we are looking into ways of using the same compiler instance over and over again: no need for loading gives better compilation times.

Since other tools running on the JVM seem to suffer from the same issues, there’s substantial infrastructure facilitating such things. Gradle has its Daemon, a long-running process (actually, it can be many processes) whose essential function is to keep tools loaded and therefore run them without the startup costs of class loading and JIT-compilation.

Try it out

We have fixed some issues that prevented Kotlin to leverage this functionality. It works reliably in Gradle 2.4 and higher (for Gradle upgrade instructions see Gradle docs). Android Studio uses the daemon by default, so you don’t have much to do, simply specify Kotlin version “0.12.1230” in your build.gradle file:

buildscript {
  repositories {
    ...
  }
  dependencies {
    classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:0.12.1230'
    ...
  }
}

NOTE: we get the full-scale speedups only after a few runs of the build. The first time we run cold and wait for the warmup, the second time most of the warmup is gone, and the build completes faster. Subsequent runs may get slightly faster too, because of the JIT.

Feedback

Please tell us if your builds have gotten faster with this change. Some project details (like LOCs and actual build times) would be appreciated.

Thanks!

image description