Kotlin's hidden costs – Benchmarks
sites.google.com
sites.google.com
Kotlin is also costly when it needs to create an object in order to pass a function (like in a non inlined higher order function). So I would expect a comparison of the number of allocations too.
From there it gets tricky because it really depends on the JVM you are running on in order to determine if this is going to generate enough pressure on the GC in order to have pauses, but that's a potential cost.
Also .. in the end the results are not that different while the 2 languages have very different capabilities. Delegates, higher-order functions, nullability, data classes, ... Kotlin has a lot to offer.
If Kotlin doesn't take advantage of them when targeting 1.8, the bytecode version won't do any difference.
(I assume)
In this case, "5-10% just isn't that much" may be the better excuse. Since Kotlin runs on the same jvm, it is a subset of Java, and therefore impossible for Kotlin to create code (and achieve speeds) that Java couldn't match.
In practice, Kotlin should asymptotically approach the performance of best-practice Java code, with possible performance improvements when it can correct unoptimised code, or implements new Java features without requiring any manual refactoring.
That probably helps a lot, because it takes significant machinery in the profiling and JIT compilers to automatically eliminate the overhead of higher-order functions and the JVM can't always do it due to a problem called "profile pollution". Kotlin pushes a bit of the thinking onto developers, albeit aided by type hints, and then does the inlining itself in many cases. Especially helpful on platforms with weaker JVMs like older Androids (the upcoming Android update appears to have improved ART so significantly that it's now a serious competitor to HotSpot).
Whilst the article doesn't show any difference in lambdas I wouldn't expect it to show up in micro-benchmarks like this one because the profile pollution problem wouldn't occur. In any real app it would show up though.
Also when Kotlin inlines on the frontend it can also use reified generics in a few cases.
Finally, Kotlin provides features that developers can use to write more efficient code, I'm thinking about how easy it makes lazyness in particular. Whilst you always can write equivalent code in Java, it takes more effort to do so, meaning developers probably won't always bother.
This doesn't follow for several reasons. First, there are JVM bytecodes that Java doesn't use, so it would be more accurate to say that JVMLangX and Java both target subsets of the JVM. Second, higher order constructs could allow a JVMLangX-to-bytecode compiler to enforce checks at compile-time that would need to be done at runtime in Java.
For people who do, do you enjoy performance optimization or does it get tedious?
It does get tedious if you need to get something out of the door fast, but have to shave off another 30% of processing time per unit of work. Honestly, I just try to partition the working set and throw more hardware at the problem in these scenarios.
It's the same.
Unless you care about a particular use case, when it isn't.
Measure, profile, refactor....