Turbo Modules is a project by Facebook that aims to improve the performance of native modules in React Native by using a new architecture.
In React Native, native modules
are modules written in native languages (like Java or Objective-C) that can be
accessed from JavaScript.
Turbo Modules optimize the communication between JavaScript and native modules, making it faster and more efficient.
Turbo Modules introduces a new
runtime layer called the Turbo Runtime which is designed to reduce the overhead
of method calls between JavaScript and native code. This can improve the significant
performance of React Native apps, especially for scenarios involving frequent
communication between JavaScript and native modules.
In React Native, native modules
are pieces of code written in the platform's native language (Java/Kotlin for
Android, Objective-C/Swift for iOS) that can be called from JavaScript.
If you have an idea about React
Native, you may be familiar with the concept of Native Modules, which allow JavaScript
and platform-native code to communicate over the React Native
"bridge", which handles cross-platform serialization via JSON.
A few Benefits of Turbo Native
Modules,
- Allowing for faster app startup
- Lazy loading of modules
- Strongly typed interfaces
- Turbo Native Modules reduce duplicate implementations across platforms
How to Create a Turbo Native
Module?
To create a Turbo Native Module,
we need to:
- Firstly, we need to define the JavaScript specification
- After that configure the module so that Codegen can generate the scaffolding
- In the last, write the native code to finish implementing the module