Android Developers Blog
Read post

How R8 made Kotlin Coroutines on Android 2x faster

Starting with AGP 9.2.0, R8 now optimizes most `Atomic*FieldUpdater` calls into direct `Unsafe` variants, eliminating costly reflective safety checks at runtime. This change delivers a 2x–4x speedup on common atomic operations and has a major impact on `kotlinx.atomicfu`, the library underpinning `kotlinx.coroutines`. As a result, launching and cancelling coroutines in Android apps — including Jetpack Compose's `LaunchedEffect` — is up to 2x faster. The post explains the root cause (ART does not JIT-optimize `AtomicReferenceFieldUpdater` the way the JVM does), walks through benchmarks confirming the overhead, and details how R8 performs the optimization in three phases: instrumentation (adding an offset field), replacement (rewriting call sites to use `Unsafe` directly), and clean-up (removing dead updater fields and initializers). Apps targeting API 36 may also benefit from similar optimizations being added natively to ART's JIT. Upgrading to AGP 9.2.0 is all that's needed to get the improvement.

    #android#kotlin#jetpack-compose
Jul 27•9m read time•From android-developers.googleblog.com
Post cover image
Table of contents
The cost of a coroutineInvestigating AtomicReferenceFieldUpdaterOptimization with R8InstrumentationReplacementClean-up
8.8K Impressions
Android Developers Blog's image
Android Developers Blog

AndroidDev's platform is a central hub for Android developers, offering insights into Android app de...

479 Followers

•

871 Upvotes

Would you recommend this post?

Copy link
WhatsApp
Facebook
X
New Squad
  • © 2026 Daily Dev Ltd.
  • Guidelines
  • Explore
  • Tags
  • Sources
  • Squads
  • Leaderboard