React Native — A Bridge To Project Fabric — Part 3

  • There are two realms: JS and Native which are not really aware of each other and do not share the same memory
  • The communication is async through the bridge between the two realms but it also means no guarantee the data will get to the other side in 100% or in the time we want
  • It is slow to transfer large chunks of data. Since the memory is not shared, all the data passed between js and native is a new copy
  • No way to update the UI in a sync way. Let's say I have a FlatList with a huge amount of data the is loaded when I scroll, the screen might flicker in some edge cases when there was a UI interaction but the data hasn’t got back yet to be shown
  • The library repo is HUGE. It makes the library heavier and also making it slower to contribute code from outside or release new fixes
The General Structure of the main pieces in the current architecture (for explaining the terms)
The General Structure of the main pieces in the new architecture (for explaining the terms)
  1. JSI (Will replace the Bridge) — Its purpose is to make the JS and Native are aware of each other. There won’t be any need to serialize JSON through the bridge and even more than that — there won’t be a bridge! It will allow to expose native object as js objects and vice-versa. It will also expose an API for synchronous calling on this object on both sides. Actually, all the rest of the architecture will be built on top of that (Fabric, Turbo Modules which will be explained next).
  2. Fabric — the new name for the UIManager which will be responsible for the native side. The biggest difference now that instead of communicating the JS side by the bridge, it will expose its native function using the JSI so the JS side and vice-versa can communication directly those ref functions. Better and efficient performance and passing data between sides.
  3. Turbo Modules. Remember the native modules from the last post? Text, Image, View. So their new name is Turbo Modules. They have the same purpose but implemented and acting differently. First, they are lazy-loaded (only when the app needs them) comparing to loading all of them on the launch time. In addition, they are also exposed using the JSI so JS holds a ref to use them on the React Native JS lib side. Result => better performance especially on launch time.
  4. CodeGen — Suppose to make the JS side a Single Source Of Truth. Can let you create static types of the js so the native side (Fabric and Turbo Modules) will be aware to them and avoid validating the data each time => better performance and less place for mistakes when passing data.
  5. Lean Core — A change in React native repository structure. The purpose is to make the lib lighter and help the community resolve more pull requests faster than before. Facebook splits some of its parts to an external repo. It is already a process in progress that you can follow in their Github here. This is how they show it =>
Inspect a page in chrome and write console.log and press Enter. You will see a native code. The console.log and other functions are actually objects exposing a ref to native code (C++ in this case)..crazy ah?
  1. User clicks on the app icon
  2. Fabric loads the native side (no native modules)
  3. It tells the JS thread that it is ready and now the JS side loads all the main.bundle.js which contains all js and react logic + components
  4. JS called through the ref native function (the one that was exposed as an object using the JSI API) to Fabric and the shadow node creates the tree as before
  5. Yoga does the layout calculation converting from flexbox-based style to host layout
  6. Fabric does its thing and shows the UI =>
  1. JSI
  2. Fabric
  3. Turbo Modules
  4. Lean Core
  5. CodeGen

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Chen Feldman

Chen Feldman

Staff Front End Software Engineer @ http://Gong.io | Tech Public Speaker | Making Software Podcast Host @ http://ranlevi.com/software