Hidden Costs and Opportunities of Kotlin versus Java on Android Runtime

University essay from KTH/Skolan för elektroteknik och datavetenskap (EECS)

Author: Johan Luttu; [2020]

Keywords: ;

Abstract: In mid-2019, Kotlin became Google’s preferred language for Android application development instead of Java. Therefore, it is in entities’ interest to migrate from Java to Kotlin for their Android projects to get the most support from Google. This study has evaluated what a Java (version 8) to Kotlin (version 1.3.50) migration would implicate for an Android application when it comes to run time performance. A set of six features was analyzed, first by a qualitative bytecode analysis, then by running microbenchmarks. The purpose of the qualitative bytecode analysis was to detect hidden costs or opportunities of Kotlin features that were not visible in the source code. The results for the analysis showed that the bytecode produced by Kotlin, compared to Java, can lead to extra workloads for the garbage collector and an increased method count for the DEX files of an Android application. It was also observed that Kotlin performs systematic boxing and unboxing for short-lived objects if primitive values are passed as arguments to, or returned from, a lambda expression for an example that included a lambda expression that was passed to a higher-order function. The purpose of the microbenchmarks was to measure the hidden costs’ or opportunities’ potential impact, and also to see if bytecode optimization tools could be relied on to mitigate the potential costs. The results showed that, in most cases, the manual optimization did not result in better performance than in the case when the code had been optimized by bytecode optimization tools. Overall, the optimized microbenchmarks showed no large differences in execution speed between the Java and Kotlin implementations.

  AT THIS PAGE YOU CAN DOWNLOAD THE WHOLE ESSAY. (follow the link to the next page)