A free Go-based Kotlin compiler, kc, builds JVM libraries 10x to 16x faster than JetBrains' kotlinc at one-tenth the RAM
Bartek Teodorczyk's kc compiles real Kotlin libraries like kotlinx.coroutines and Ktor in a fraction of a second, against seconds for a warm kotlinc. It's a prototype that skips most of kotlinc's checks, and its README lists exactly what it leaves out.
The README gives four reasons for the speed. kc has no JVM to start, so it “starts in milliseconds,” where a cold kotlinc spends seconds warming up. It parses, checks and writes class files on every core, while kotlinc’s front end uses one. It writes code in a single pass, where kotlinc’s time is “spread over 88 IR lowerings and 290 checkers, none above about 2%.” And it indexes the class path in about 5 milliseconds, decoding a class only when something uses it.
Cold starts are where the gap gets wide. With a fresh JVM per build, the way a command line or a CI runner does it, kotlinc took 6.9, 19.2 and 10.9 seconds on the three libraries, 69 to 85 times slower than kc. Peak memory for kc was 85 to 118 MB, and cold kotlinc with an 8 GB heap limit reached 1.0 to 1.1 GB.
The README is as plain about what kc doesn’t do. It leaves out some of the language, and it doesn’t check visibility. It agrees with kotlinc on only 79% of the diagnostics tests, because it reports only the errors type checking finds. There’s no Kotlin/Native, JavaScript or Wasm, no incremental compilation, no Gradle plugin and no IDE support. Its class files “work the same, but differ in places”: for kotlinx-coroutines-core it writes 790 classes where kotlinc writes 850, because it shares the objects of inline functions instead of copying them.
The list of unsupported Kotlin is the document to watch. The repo went up on October 31, and the benchmark notes give the scripts to repeat every number, so the first outside timings on someone else’s machine are one clone away.