Measuring Kotlin Build Performance at Uber

Edgar Fernandes, Thales Machado, Tho Nguyen, Zac Sweers
20 min readadvanced
--
View Original

Overview

This article discusses the evaluation of Kotlin build performance at Uber, focusing on the transition from Java to Kotlin in their Android applications. It highlights the design considerations, project generation workflow, experiment execution, and the results of their analysis, providing insights into the performance implications of adopting Kotlin.

What You'll Learn

1

How to measure Kotlin build performance at scale

2

Why to consider project structure when adopting Kotlin

3

When to use Kotlin versus Java in large repositories

Prerequisites & Requirements

  • Understanding of Kotlin and Java programming languages
  • Familiarity with build systems like Buck or Gradle(optional)

Key Questions Answered

What are the key design considerations for measuring Kotlin build performance?
The key design considerations include ensuring code is functionally equivalent, using non-trivial code that reflects real-world conditions, and measuring across a diverse set of large modules. This approach allows for a comprehensive understanding of how different project structures impact build performance.
How does Kotlin's build performance compare to Java's?
Kotlin projects resulted in 40 percent fewer lines of source code than Java for functionally equivalent code. However, Kotlin with Kapt showed a significant overhead of approximately 95 percent compared to pure Kotlin, indicating that while Kotlin can reduce code size, its build performance can be impacted by annotation processing.
What were the results of the Kotlin build performance experiments?
The experiments revealed that Kotlin's performance was consistent across different configurations, with javac and kotlinc showing similar compilation times. The total compilation time grew linearly with project size, indicating that larger projects do not exponentially increase build times.

Key Statistics & Figures

Lines of code reduction
40 percent fewer lines of source code
Kotlin compared to Java for functionally equivalent code.
Overhead of Kotlin with Kapt
95 percent overhead
Compared to pure Kotlin.
Total number of projects analyzed
354 projects
Generated for the experiments.
Total number of experiments run
129 experiments
Conducted to evaluate Kotlin build performance.

Technologies & Tools

Some links below are affiliate links. We may earn a commission if you make a purchase.

Programming Language
Kotlin
Used for developing Android applications at Uber.
Programming Language
Java
Previously used for Android applications before transitioning to Kotlin.
Build System
Buck
Used for building Android applications at Uber.
Annotation Processing Tool
Kapt
Used for Kotlin projects to generate code during compilation.

Key Actionable Insights

1
Evaluate the impact of project structure before adopting Kotlin in large repositories.
Understanding how different project structures affect build performance can help in making informed decisions about language adoption, especially in environments with high commit throughput.
2
Consider the overhead of using Kapt with Kotlin.
Since Kapt adds significant overhead, it may be beneficial to explore alternatives or optimizations that can mitigate this impact, particularly in performance-sensitive applications.
3
Utilize the project generation workflow to analyze build performance.
By generating diverse project configurations, teams can gain insights into the trade-offs of different setups, helping to optimize build times and overall developer productivity.

Common Pitfalls

1
Relying too heavily on Kapt can significantly slow down build times.
Kapt's overhead can be detrimental in performance-sensitive environments, and teams should consider alternatives or optimizations to mitigate this.
2
Assuming that Kotlin will always result in faster builds compared to Java.
While Kotlin can reduce code size, the performance implications of using Kapt and other factors must be carefully evaluated.

Related Concepts

Kotlin Vs. Java Performance
Build Systems And Their Impact On Performance
Annotation Processing In Kotlin