Old architecture vs. new architecturePart 11 of 14
Turbo Modules
Lazy, cached, typed native modules, and the alternatives built on the same layer
AdvancedVerified on React Native 0.88Updated 6 December 2026
Read first: Codegen, JSI (JavaScript Interface), Sync vs. async native calls
The big idea#
A Turbo Module is a native module made of a spec, Codegen glue and an implementation, exposed to JavaScript as a JSI HostObject. It's registered at startup but created only on first use, then cached, and cleaned up when the runtime is torn down.
Concepts#
Lifecycle: lazy lookup#
Turbo Module lookup
Boxes: JS lookup (getEnforcing); TurboModuleManager (Check cache); Return HostObject (Cached for reuse); Provider creates (Package or provider); Wrap in JSI glue (…SpecJSI). Arrows: JS lookup to TurboModuleManager; TurboModuleManager to Return HostObject (hit); TurboModuleManager to Provider creates (miss); Provider creates to Wrap in JSI glue; Wrap in JSI glue to Return HostObject.
- JavaScript
- C++
- Other
- Native
Registration. On Android, a package class describes the modules without creating them:
class CalculatorPackage : BaseReactPackage() {
override fun getModule(name: String, ctx: ReactApplicationContext): NativeModule? =
if (name == NativeCalculatorSpec.NAME) CalculatorModule(ctx) else null
override fun getReactModuleInfoProvider() = ReactModuleInfoProvider {
mapOf(NativeCalculatorSpec.NAME to ReactModuleInfo(
name = NativeCalculatorSpec.NAME,
className = NativeCalculatorSpec.NAME,
canOverrideExistingModule = false,
needsEagerInit = false,
isCxxModule = false,
isTurboModule = true))
}
}On iOS, modulesProvider in codegenConfig maps the JS name to the Objective-C class.
get vs. getEnforcing. TurboModuleRegistry.get returns null when a module is missing (for optional modules); getEnforcing throws "could not be found". Usual causes: native code not rebuilt, autolinking missed the package, mismatched names (the getEnforcing string, NAME on Android and moduleName / modulesProvider on iOS must be identical), or an OTA bundle newer than the binary.
Eager init. needsEagerInit = true creates the module at startup. Reserve it for modules that must exist before any JS runs, such as crash reporters.
Cleanup. When the runtime is torn down (development reload, host destroyed), invalidate() is called on every created module. Remove listeners, stop timers, close sockets and stop threads there.
Constants#
export interface Spec extends TurboModule {
getConstants(): { apiVersion: string; maxPrecision: number };
}Constants used to be computed for every module at startup. Now they're an ordinary synchronous call, made only when JS asks for them, so call it once and keep the result.
Events: native → JS#
Typed events in the spec:
import type { TurboModule, CodegenTypes } from 'react-native';
export interface Spec extends TurboModule {
startWatchingRate(currency: string): void;
stopWatchingRate(): void;
readonly onRateChanged: CodegenTypes.EventEmitter<number>;
}Codegen generates emitOnRateChanged(value) for native code to call:
emitOnRateChanged(0.712)const sub = NativeCalculator.onRateChanged(rate => setRate(rate));
sub.remove();The legacy pattern (common in existing libraries): addListener / removeListeners in the spec, new NativeEventEmitter(module) in JS, and emitDeviceEvent / sendEventWithName: in native code. Untyped, but still working.
Events can be emitted from any native thread; they're scheduled through CallInvoker as tasks, so listeners always run on the JS thread. Treat callbacks as one-shot, and use events for anything repeated.
Threads and queues#
| Android | iOS | |
|---|---|---|
| Sync methods | JS thread | JS thread |
| Async methods | Native-modules thread | The module's methodQueue (serial, per module) |
| Need the UI thread | UiThreadUtil.runOnUiThread { … } | dispatch_async(dispatch_get_main_queue(), …) |
Binary data with ArrayBuffer (0.88)#
A spec can declare process(data: ArrayBuffer): ArrayBuffer instead of Base64 strings. Synchronous methods can borrow JS memory, in which case the bytes are valid only until the method returns. To keep them, copy during the call with ArrayBuffer.arrayBufferWithCopiedBytes(data). Touching a revoked borrowed buffer throws IllegalStateException.
Pure C++ Turbo Modules#
class NativeCalculator : public NativeCalculatorCxxSpec<NativeCalculator> {
public:
explicit NativeCalculator(std::shared_ptr<CallInvoker> jsInvoker)
: NativeCalculatorCxxSpec(std::move(jsInvoker)) {}
double add(jsi::Runtime &rt, double a, double b) { return a + b; }
};A pure C++ module gives you one implementation for both platforms and no JNI hop on Android, but no direct access to platform APIs. It's best for pure logic: parsers, crypto, compression, math.
Turbo Modules vs. Expo Modules vs. Nitro#
Three ways to write a native module
| Turbo Modules | Expo Modules | Nitro Modules | |
|---|---|---|---|
| Source of truth | TS spec + Codegen | The native code (Swift/Kotlin DSL) | TS spec + nitrogen |
| iOS language | ObjC++ (Swift via a .mm wrapper) | Swift | Swift (Swift–C++ interop) |
| Android language | Kotlin/Java | Kotlin | Kotlin |
| Shape | One singleton per name | Modules and views, short DSL | Hybrid objects, many instances |
| Maintained by | Meta (official) | Expo | Margelo (community) |
| Best for | The standard; core libraries | Fast development | Maximum performance |
// An Expo module, for comparison
public class CalculatorModule: Module {
public func definition() -> ModuleDefinition {
Name("Calculator")
Function("add") { (a: Double, b: Double) in a + b }
AsyncFunction("fetchRate") { (currency: String) in 0.709 }
Events("onRateChanged")
}
}Myths vs reality#
Myth
Turbo Modules load lazily, so module setup never affects startup
Reality: creation is lazy but synchronous. Heavy constructors move the cost to the first call, and needsEagerInit brings it back to startup.
Myth
A module that extends ReactContextBaseJavaModule is legacy
Reality: the generated Java Spec itself extends ReactContextBaseJavaModule. A module is new-architecture when it extends a generated Native…Spec; extending ReactContextBaseJavaModule directly is the legacy pattern.
In practice#
Checklist for reading or patching a module:
package.json→codegenConfig→ the specs.- Android: the package class (
getModule,ReactModuleInfo) and the module extendingNative…Spec. - iOS:
modulesProvider→ the class conforming to the generated protocol →getTurboModule:. - Events:
EventEmitterin the spec (modern) oraddListener/removeListeners(legacy). invalidate(): a module that starts threads or listeners without one is a likely leak.- Threading: sync methods doing I/O, or async methods hopping to the main thread, are common performance bugs.
In one sentence
A Turbo Module is registered at startup, created on first use and cached as a JSI HostObject until invalidate(), with constants read lazily and events sent back through typed emitters on the event loop, and the same JSI layer also powers C++ modules, Expo Modules and Nitro.