It's very early still, but I thought I'd share in ...
# multiplatform
r
It's very early still, but I thought I'd share in case anyone is curious. I've built bazel support for KMP. In our monorepo it makes CI 4-20x faster (biggest wins on iOS) when coupled with some additional optimizations, and lets us distribute most of the iOS CI to Linux arm64 workers. We are also able to share the CI cache with developer laptops, as the keys and outputs are byte-identical. github.com/voize-gmbh/rules_kmp
❤️ 3
😯 3
🆒 3
o
@Reuben Morais Could you elaborate on what your test set looked like and what exactly was contributing to the speed gains?
r
I'll do a proper write up at some point, but here's some details: We have a KMP product monorepo: • ~210 Gradle modules (145 KMP libraries, ~50 JVM-only), ~2.2M lines of Kotlin, about a third of the files tests • JVM, Android and iOS targets (plus a little JS/Wasm) • builds 5 Android apps (several flavors each), 4 iOS apps and a few JVM services as container images • ~2,200 Maven artifacts, ~500 test targets (JVM, Robolectric/Paparazzi, iOS simulator) I ran our main CI jobs on Bazel, each with its own independent cache, in three states: cold, no-op, and edits to some files representative of recent MRs. Remote execution ran on one 64-vCPU Graviton machine, and the Mac work ran on our existing Mac Studios. The Gradle baseline is the median job time of that day's real MR pipelines, with a warm build cache. The comparison is not perfectly apples-to-apples, but the gaps are large (Bazel edit vs Gradle): • iOS simulator tests: 3.5 min vs 30 min • iOS app: 5 min vs 15 min • all JVM/Android tests + detekt/ktlint: 5 min vs 23 min • compile everything: 2 min vs 10 min Cold Bazel runs are not faster (15–35 min). Locally, Gradle still wins small edits inside JVM-only modules. Where the speed comes from, biggest first: 1. A K/N static cache per module. By default Gradle only caches external libraries, so our own code gets compiled to native code again in every test binary and framework link. Bazel compiles each module's cache once, as a cached action, and every link reuses it. 2. ABI-only klibs. Each klib is also written as a header klib (public ABI + inline bodies) that dependents compile against. So a body change in a core module rebuilds only that module: one of our big iOS test binaries went from ~7 min to 37 s. 3. K/N work moved off the Macs. With a K/N patch, klibs and static caches for Apple targets compile on Linux, byte-identical to the Mac's. The Macs, our scarcest CI machines, only do cinterop, linking and Swift. 4. A fine-grained remote cache, tests included. Tests whose inputs didn't change don't rerun. Sharing a cache between laptops, Linux and Mac meant making outputs byte-identical everywhere (paths in debug info, archive file modes, SDK paths). 5. Android: rules_android patches (desugar against header jars, dex grouping, one-pass APK packaging). Locally, after a body change in a core module, the APK is rebuilt in 7 s, where Gradle takes 28 s. What it took: the BUILD files are generated from an export of the Gradle model, so Gradle stays the source of truth during the migration. On top of that, patches to K/N, rules_android, rules_swift and apple_support, a few of them already sent upstream.
o
Thank you, that's impressive and the details are really helpful for folks who might want to explore a different approach to builds. Of course, it would be interesting to know how the picture would change if you'd keep K/N caches between jobs. In case these experiences might interest the Kotlin Build Tools team: CC @Adam Semenenko
✅ 1
r
updated the numbers above with ~/.konan caching enabled in gradle
thank you color 1