How a Kotlin compiler plugin cut Android time to first render by 30%
Blog post from Expo
Expo SDK 56 introduces a Kotlin compiler plugin that significantly enhances performance by eliminating reflection from Expo Modules on Android, resulting in a 70% faster module initialization, a 30% reduction in time to first render, and Record conversions that are approximately six times faster than in SDK 55. This performance boost is automatically applied during compilation without requiring any code changes from app developers, while module maintainers can opt into the faster Record conversion with a single annotation. The post explains the evolution from Unimodules to the current Expo Modules API, highlighting the limitations of reflection in terms of startup time and the challenges faced in addressing these issues. The new K2 compiler, with its plugin API, allows for direct editing of intermediate representations, thus avoiding the need for code generation and the complexities it brings. The plugin substitutes runtime reflection with pre-computed type descriptors and baked-in Record metadata, offering a more efficient alternative to the traditional reflection-based methods. The approach is poised to expand further, aiming to enhance other parts of the module lifecycle while maintaining the API's ergonomic design.