Expo Modules 2.0’s Kolibri JNI layer cuts some Android calls by up to 51×
Brief
Expo’s Kolibri is a new JNI layer for Android in Expo Modules 2.0, designed to reduce overhead when Kotlin, C++ and JavaScript exchange calls and data.
Benchmark results
- Calls into C++ hybrid objects measured 2.7 ns with Kolibri, versus 76–138 ns with fbjni, depending on the fbjni implementation.
- For JS objects passed to Kotlin, the binary-buffer approach was 3–5× faster in the examples highlighted by Expo; gains reached 13× for an array of 1,000 numbers.
- Kolibri’s calls from C++ into Java were generally within about 2% of raw JNI in the reported benchmarks.
How Kolibri works
- Kolibri combines a C++ library, a Kotlin runtime and a Kotlin compiler plugin; it can omit exception checks for methods marked as non-throwing.
- It passes JS data through a shared direct ByteBuffer rather than constructing each Java value through separate JNI calls.
- The benchmarks used an Apple M3 Pro with JDK 17 and a desktop JVM, so the article notes that absolute times on phones will differ.
Generated by AI from the original article. Check the source for full details.