The explanations could be: a) the bytecode generated by the Kotlin compiler is much worse and b) the benchmark Kotlin code is not as good or optimized as the Java one.
The explanations could be: a) the bytecode generated by the Kotlin compiler is much worse and b) the benchmark Kotlin code is not as good or optimized as the Java one.
https://github.com/LesnyRumcajs/grpc_bench/blob/master/kotli...
https://github.com/LesnyRumcajs/grpc_bench/blob/master/java_...
Looking at the build files, different versions of the libraries appears to be used. The Java implementation is configurable but defaults to something called "direct executor".
Maybe that explains the difference.
In my case, I have a programming language interpreter implemented in Kotlin, and as an experiment I made the entire interpreter using suspending calls so that I could call asynchronous functions, and my performance tests dropped by about 20%.
Irreducible loops make many optimizations much more complex. Bytecode generated by javac never contains irreducible loops, and since bytecode generated by javac is the number 1 use case targeted by JVM JIT compilers, they probably just don't bother trying to be that smart about irreducibility.
* Exception is supporting things like default methods on JVM 1.6 bytecode
Additionally it is stuck on Java 8 view of the world, otherwise those .class files won't be usable on Android toolchain thanks Google.
I know for a fact it uses different bytecode features if the level is >= 1.8, not sure how smart it is above that.
Going forward while for Java code there is no worry about using SIMD, JNI replacement, value types, Kotlin code will need to make use of KMM for code that is supposed to target both JVM and Android.
It can do stuff android doesn't support if you set the bytecode target level to > 1.8
It's like using modern Javascript features but providing a polyfill for older browsers.
Also stuff like value classes will have different semantics in memory consumption and performance across targets.
Maybe some learning required?
You are either being deliberately obtuse or you genuinely have difficulty to understand that Java version, bytecode version, Kotlin compiler output and what bytecode Android supports are totally independent concepts.
It is going to be fun to port back stuff to Java.