Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

Meta Engineering 10 min read Case study mediumAdept

Enabling Kotlin incremental compilation on Buck2

Meta integrated the Kotlin incremental compiler into Buck2 via Kotlin's experimental Build Tools API, making some large Android modules build up to 3x faster and improving incremental build times about 30% for the average developer. The work involved migrating the toolchain to the shaded kotlin-compiler-embeddable, using Buck2 incremental actions to keep prior outputs and compute changed-file lists from input hashes, making the cache relocatable for remote execution, and generating classpath snapshots as a separate cacheable action. Custom compiler plugins had to be made incremental and accumulate results across multiple compilation rounds. jvm-abi-gen still lacks incremental support, so a stopgap merges the new ABI with the previous output.

Related posts

  • Build faster with Buck2: Our open source build system

    Meta Engineering mediumAdept

    Buck2 is Meta's from-scratch rewrite of Buck, open sourced with a Rust core and all language rules written in Starlark, and it completes builds about twice as fast as Buck1 internally. Its speed comes from a single incremental dependency graph held by a persistent daemon instead of separate target/action graph phases, plus Bazel-compatible remote execution and integration with virtual file systems via Watchman and Sapling. New rule primitives make complex patterns safe and efficient: dynamic_output lets rules run tools like ocamldep and wire dependencies from their output, and transitive-sets (tsets) avoid O(n²) memory for C++ link closures. The open source release is nearly identical to Meta's internal version and is aimed mainly at moderately sized multi-language projects.

  • Extending Anvil for Fun and Profit

    Slack Engineering hardMaster

    Slack's Android app replaced dagger-android activity injection with a custom Anvil code generator: annotating an activity with @InjectWith(scope) generates an AnvilInjector wrapping Dagger's intrinsic MembersInjector plus a @ContributesTo binding module that adds it to a scope-level multibinding map. BaseActivity looks up the injector from the scoped component in onCreate() and calls inject(). Built on Anvil 2.3.0's compiler-api, it runs inside kotlinc with no kapt or dagger-android-processor, avoids runtime reflection, and generalizes to any member-injected type such as services and jobs. Anvil's factory generation alone cut incremental build times by up to 25%.

  • 5 Things you didn’t know about Buck2

    Meta Engineering easyNovice

    Buck2, Meta's open-source successor to the Buck build system, completes builds roughly 2x faster than Buck1 in internal tests. Its core is written in Rust, chosen over Java, Haskell and Go for performance, memory control without GC over large graphs, and safe concurrency, while rules are written in Starlark. With remote execution it can skip downloading intermediate outputs by tracking only their hashes. It uses 11 distinct path types for type safety, keeps all language knowledge out of the core in a replaceable Starlark prelude, and offers BXL for querying the build graph and defining new actions, for example to generate IDE projects.

  • From zero to 10 million lines of Kotlin

    Meta Engineering mediumAdept

    Meta has converted its Android codebase to over 10 million lines of Kotlin by wrapping JetBrains' J2K converter in an automated pipeline called Kotlinator. The pipeline preprocesses Java packages, runs J2K headlessly through Android Studio, then applies automated refactors and linters built on the Kotlin compiler's PSI AST. Those refactors fix issues such as JUnit @Rule annotations needing @JvmField or @get:Rule, and replace TextUtils.isEmpty with isNullOrEmpty. Meta chose a full conversion over Kotlin-for-new-code-only to avoid platform-type null risks from Java interop. Results: about 11% fewer lines, no runtime performance regression in A/B tests, negligible APK size impact after Proguard/Redex, and longer build times as the main cost.

  • Kotlin Multiplatform in Production: Two Real-World Use Cases from Booking.com

    Booking.com Engineering mediumAdept

    Booking.com applied Kotlin Multiplatform in two production cases: a shared experimentation library replacing drifting Java/Kotlin and Objective-C implementations, and a Compose Multiplatform (Kotlin/JS) web playground that renders the real Android BUI design-system components in a browser. The experimentation library ships as a Gradle dependency on Android and an XCFramework via CocoaPods on iOS, and was validated by running old and new implementations side by side behind experiment flags. During that parallel phase iOS saw roughly +140 ms p90 startup and +2.5 MB download size, but startup improved once the legacy code was removed, which shows migration-time performance data can mislead. iOS engineers were brought on board through an evaluation framework with an explicit exit ramp, and some later became contributors, though Xcode's lack of Kotlin support remains a tooling gap.

The quest for software engineering knowledge.

Look:
Layout: