Kotlinc as a native binary

This started from a discussion in


$ time -p kotlinc hello.kt
real 11.54
user 14.12
sys 0.66

For comparison, rustc compiles hello world in 0.2 secs.

As long as you’re using gradle, an IDE running on JVM etc this is ok. But in order to compete with rust and go, I think kotlin needs to have a faster startup time, so one can use it from Makefiles or simple command line usage.

I’m trying to understand what the limitations here are. Why is kotlinc a “huge JVM program”?

My quick grep:

~/src/kotlin/compiler$ ack -h import.*java | sort | uniq -c | sort -rn | head -40 | pastebinit

tells me that all of these java.util dependencies can be replaced with calls to kotlin stdlib.

So what are some of the impediments to building a native compiler with a quicker startup time?

Here’s hopefully a clickable link:


You also forgot about all java.lang which imported automatically and about other Java dependencies, the biggest one of them is Intellij Platform itself to work with Java code (after all you need full java interop)

Also you should check all usage of threading in compiler, they cannot be ported directly to K/N

For quicker startup time its probably much more efficient try to play with AOT bundles of compiler

Another thing for consideration is that usage of compiler directly for compiling a single file, without any build system has pretty limited use cases (but I don’t say that they do not exist, just that they much more limited)


Yes - the analysis I posted was by no means complete in terms of the work required and AOT is an option I’d consider. The ktlint program seems to be one such binary and had a pretty good startup time.

However, I’d like you and jetbrains to think about the mind share (as opposed to market share or short term benefits) a fast CLI compiler on linux would give you, beyond just the android/mobile market.

Things that you could improve:

  • Size of the hello world binary - 492kb (unstripped), 328kb (stripped)
  • Output name: program.kexe, most people on linux expect hello or a.out

Rust isn’t doing great in that department either, but rust has competition :slight_smile:

I think JetBrains does publish AOT compiled version of kotlinc for the purpose of speed and compiling scripts. Maybe someone remembers which blog post mentions it but I suspect you could find it published on GitHub?

1 Like

because they wanted to “save development time” and “can reuse existing language”, and “easier to write than c++”

in the end, poor result, and they waste time trying “optimizing” everything in vain

that is what happen when clueless people are driving huge projects, they make bad decisions for short term gains (even that is debatable)

the only solution for kotlin native to become usable outside of “bridging java to iOS” is to rewrite everything in a data oriented way

but management is clueless, so that will never happen

people who don’t know how computer works, shouldn’t be working in tech