Compiling Kotlin is x100 slower than Java

Profiling Gradle builds of our project revealed that it spends on average same time compiling java as we spend on Java, however only ~1% of the codebase is Kotlin yet.

Anybody faced such issue?

Project stats:
Gradle plugin version: 3.4.2.
Kotlin version: 1.3.41.
Modules: 17.
Lines of code: Java ~700k, Kotlin ~ 7k.
Compilation summary: compileDebugJavaWithJavac ~ 20s, compileDebugKotlin ~ 20s.

Does the Kotlin compilation phase include the Java code compilation?

Are Java and Kotlin code partitioned in two different modules or are they mixed in a single one?

Before introducing Kotlin, did the whole project compilation take 21 seconds to complete?

1 Like

@fvasco, thank you.

Does the Kotlin compilation phase include the Java code compilation?

No, I pulled times for separate Kotlin and Java compilation phases from Gradle “–scan” report. These tasks are executed by gradle separately one after another for each module.

Are Java and Kotlin code partitioned in two different modules or are they mixed in a single one?

~5 of 17 modules have Kotlin code alongside Java code. The rest are pure Java.

Before introducing Kotlin, did the whole project compilation take 21 seconds to complete?

20 seconds is not project compilation time, but execution time of compileDebugJavaWithJavac task (phase). It didn’t visibly change since introducing Kotlin.

Hi @maff91,
take a look here

https://kotlinlang.org/docs/reference/using-gradle.html

Please consider to upgrade your Gradle version at least to 4.3.

In my experience first compilation take really longer than others.

Hi @fvasco,

upgrade your Gradle version at least to 4.3

Gotcha, thanks. As I mentioned we use Gradle Plugin 3.4.2 which corresponds to Gradle version 5.1.1.

Ah, ok, sorry,
I am not an Android insider.

Hi @maff91,
unfortunately I cannot help you a lot, but I wish to leave you the last tip, hoping it helps.

I read about some slowing caused by apt/kapt, take a look here https://kotlinlang.org/docs/reference/kapt.html#gradle-build-cache-support-since-1220

Similarly you can consider to continue your search in an Android community.

Good luck!

Thank you, @fvasco, appreciate it!

26.s increment compilation

10 Likes