Why is Kotlin Native much slower than JVM?

Did you enable optimization in the conan backend? The JVM JIT compiler optimizes quite well taking into account actual usage data. For native binaries you can do this (if you have a test suite) by using profile guided optimization (where you create a profile generated by running the test suite to tune a second optimization/compilation go). On modern hardware the difference between optimization and non-optimization can make a very significant difference.

Having said that, Kotlin native is not quite ready for stable release yet and I don’t think that optimization is one of the key priorities. Of course the standard LLVM backend optimizations are available, but Kotlin specific optimizations may not be. Overall native being slower in the hot path than JVM is not surprising (the JVM generates/runs native code, is not an interpreter), but it should not be the size that you are observing.

6 Likes