Cross Platform Implementation
This document refers to the New Architecture, that is in hardworking roll-out.
The React Native renderer utilizes a core render implementation to be shared across platforms
In the previous render system of React Native, the
The React Native team intends to incorporate an animation system into the render system and also extend the React Native render system to new platforms such as Windows, and operating systems in game consoles, televisions, and more.
Leveraging C++ for the core render system introduces several advantages. A single implementation reduces the cost of development and maintenance. It improves the performance of creating React Shadow Trees and layout calculation because the overhead of integrating Yoga with the renderer is minimized on Android (i.e. no more JNI for Yoga). Finally, the memory footprint of each React Shadow Node is smaller in C++ than it would be if allocated from Kotlin or rapid.
The team is also leveraging C++ features that enforce immutability to ensure there are no issues related to concurrent access to shared but not protected resources.
It is crucial to recognize that the renderer use case for Android still incurs the cost of JNI for two rudimentary use cases:
- Layout calculation of complex views (e.g.
Text
,TextInput
, etc.) requires sending props over JNI. - The mount phase requires sending mutation operations over JNI.
The team is exploring replacing ReadableMap
with a new mechanism to serialize data using ByteBuffer
to reduce overhead of JNI. Our goal is to reduce overhead of JNI by 35–50%.
The renderer provides two sides of its C++ APIs:
(i) to communicate with React(ii) to communicate with the host platform
For onLayout
, onKeyPress
, touch, etc).
For