How a Kotlin compiler plugin cut Android time to first render by 30%
Article Summary
Łukasz Kosmaty from Expo just shipped a compiler plugin that cuts Android app startup time by 30%. No code changes required for developers.
Expo SDK 56 introduces a Kotlin compiler plugin that eliminates reflection overhead from module initialization. The plugin transforms expensive runtime operations into compile-time code generation, targeting the two biggest bottlenecks: type metadata resolution and Record object conversion.
Key Takeaways
- Module initialization runs 70% faster by replacing runtime reflection with compile-time descriptors
- Record conversions accelerate 6x with a single @OptimizedRecord annotation
- Cold launch improved from 93ms to 55ms in module-heavy test apps
- Plugin intercepts typeDescriptorOf() calls and swaps in pre-computed type objects
- K2 compiler's IR access enables surgical code modifications without fragile bytecode manipulation
Expo SDK 56 automatically delivers 30% faster time to first render on Android by moving reflection work from runtime to compile time.
About This Article
Expo Modules used runtime reflection to figure out type information for function arguments and Record properties. This meant the JVM had to parse binary @Metadata annotations and rebuild Kotlin's type system every time the app launched cold.
Łukasz Kosmaty's team wrote a K2 compiler plugin that catches typeDescriptorOf() calls and @OptimizedRecord annotations at compile time. Instead of using reflection, it swaps them out for pre-computed type descriptors and baked-in Record metadata that use direct index-based field access.
Cold launch Activity.onCreate improved from 93ms to 55ms, a 41% drop. Time to first render went from 797ms to 508ms, down 36%. Record conversion became about 6x faster than SDK 55. App developers didn't need to change any code.