The Future of React Native with Fabric Test

by | Nov 12, 2018

 

The main criticism of any cross-platform mobile development framework is inevitable if small, loss of performance when juggling native elements and cross-platform elements; if your app calls to a device camera, Bluetooth, microphone, or otherwise, you are familiar with the loss of precious milliseconds. React Native is looking to dispel this criticism with its upcoming updates in Fabric and Turbo Modules.

 

What is React Native?

React Native Logo

What is React Native? React Native is the cross-platform framework built by Facebook for building apps for Apple, Android, and other devices in the future, and is used for apps today like Bloomberg, Walmart, Uber, and others. The React Native framework uses Javascript for building its Components and allows developers to call directly to native modules using Objective C and Java within its code.

 

With that kind of support, adoption, and ease of use, you would assume that they’ve solved the issue of performance, right? Not until now with Fabric and Turbo Modules.

 

What is the Problem?

 

Javascript is a performant language used all over the web, so this should be a simple problem to solve, right? Not quite. As Ram N from Facebook explained at the 2018 React Conference, React Native applications work currently by moving across 3 different layers: platform/UI, layout, and Javascript.

 

React native platform UI layout Javascript frame

 

In order to display Javascript on the platform, you need to pass it through a layout handler and React Native typically handles this in an asynchronous manner. This communication needs to be asynchronous due to the typical disparity of load: the UI layer usually does the least amount of work, where the Javascript layer is where business and product logic is handled. To make things worse, when moving between the layout and Javascript layers, information needs to be converted to serialized JSON and back again, causing extra effort to return the results from the Javascript layer.

 

React native platform UI layout Javascript JSON

 

In an example highlighted by Ram, a user could be scrolling through a long list of data points quickly, which is sending the onScroll event to the Javascript layer requesting more information for their user in an asynchronous method, usually. This is the critical point in a mobile app user experience that differentiates between a great app and a good app: the screen flickers, sputters and fails to load the content at the speed that the user needs it, and the user is taken out of their experience.

React native platform RAM Loading

 

How Do We Fix This?

 

Valentin Shergin, one of Facebook’s engineers depicted this problem in the below nightmare diagram, emphasizing that, by using these three layers, we’re stuck with repetitive calls across these layers and lost performance as a result (or, as he calls it, a non-flattened experience). This repetition causes inefficiencies in memory distribution across Javascript and native.

 

Javascript and Native without flattening and with flattening reach native

 

Using Turbo Modules

 

Here’s where Fabric and Turbo Modules come in.

 

Through a method Facebook is dubbed JSI or Javascript Interface, a unified lightweight API able to be used by any Javascript VM. React Native can focus on the conversation between Javascript and Java/Objective C, and emphasizes hosting objects and exposing methods/variables to Javascript. Javascript can avoid making the heavy calls of serialized JSON by referencing objects in JS rather than calling to them directly and focusing on calling native elements first.

 

Ram N explained this with a Camera module; here’s the module using the current method, where serialized JSON is being passed between the platform and Javascript to get the picture host object:

 

RAM N Camera module Javascript

 

Here’s a version using JSI where the picture host object is referenced rather than called/translated:

 

RAM N Camera module Javascript

 

Once the JSI has called the JSI host object, methods can be called on the object using Javascript, and returned values themselves can even be classified as host objects.

 

Using Fabric to Manage UI

 

React Native will be able to run certain heavier calls synchronously, prioritized over other UI elements, to return information quicker to reduce the chance of flickering by using their new UI Manager dubbed Fabric.

 

Per Valentin Shergin, an engineer at Facebook, Fabric focuses on the following top strategies:

  • Using C++ for cross-platform “shadow” layer (in place of the Layout layer above)
  • Immutable data structures (Shadow Trees, Props, Events)
  • Shared memory ownership (between JS and native)
  • Type-safe data structures
  • Opt-in synchronous execution where it benefits performance, the UI responsiveness and simplifying inherently-synchronous interop APIs.

With Fabric, you’ll be able to worry less about relying on non-performant asynchronous calls and can instead only make costly calls out to Javascript objects when absolutely necessary.

Ram N depicted the benefits of this new system with the following diagrams. In this initial diagram, you see the current method, where dotted lines represent an asynchronous call, blue boxes represent background processes, and green boxes represent the UI thread.

 

Ram N React Native initial diagram

 

Using Fabric, you can prioritize certain calls to be prioritized and sent synchronously, as shown in the onScroll event below. The user would receive the information they’re expecting while scrolling much faster since they don’t need to wait for an asynchronous call to be completed.

 

React Native New Way

 

Why Is This Exciting for React Native?

 

React Native is a widely used framework that allows businesses to streamline their cross-platform app dev, but, like any cross-platform development, the creeping annoyance of lacking performance with native modules is always a criticism brought up during discussions of which framework is best. With these changes, businesses can worry less about the optimization of their experiences and can know that they’re delivering an experience close to native.

 

When Can I Optimize My Apps?

 

Fabric and the use of Turbo Modules are still in development, but you can follow their progress via their Github thread. You can also find Ram N’s full talk from the 2018 React Conference here. In the meantime, check out our React Native white paper on how we can help you deliver your business value using React Native cross-platform dev.

 

Cameron Hall

Cameron Hall

Mobile Strategist

Cameron uses his experience in app and analytics strategy for healthcare, finance, government, and logistics apps with a focus on emerging technologies to deliver on customer-centric product development. When not devouring research on the latest and greatest, you can find Cameron hiking, playing soccer, reading a book, or continuing his education.

Cross-Platform Design Strategy Tips in 2019

Cross-Platform Design Strategy Tips in 2019

Android and iOS users have been at odds for over a decade. Each platform carving out its path and even stepping on each other's toes in the process. However, for many consumer app developers to pick a side would mean to ignore a large chunk of users....

3rd time’s a charm: Shockoe Makes Inc. 5000 List Again

3rd time’s a charm: Shockoe Makes Inc. 5000 List Again

Inc. Magazine Unveils Its Annual List ofAmerica’s Fastest-Growing Private Companies—the Inc. 5000For the 3rd Time, Shockoe Appears on the Inc. 5000,Ranking No. 1051 With Three-Year Revenue Growth of 445 Percent RICHMOND, VA, August 14, 2019 – Inc. magazine...

Designers Unite: Shockoe to host AIGA

Designers Unite: Shockoe to host AIGA

We have a small but mighty design team here at Shockoe. Any given day one of us might be discovering needs from a client, drafting UI standards for another, then refining designs for the most intuitive and impactful experience. With so many facets to everyday...

Clutch Names Shockoe a Top Developer in Virginia

Clutch Names Shockoe a Top Developer in Virginia

Align Mobile Technology to Human Behavior Shockoe brings a holistic view of what it take to bring emerging technology to the edge. We bring a deep experience in mobile apps and the latest in AR and voice technology. Understanding the changing world of software...

There’s an Alternative to Rest API: GraphQL

There’s an Alternative to Rest API: GraphQL

Recently I was asked to update a Node.JS server to replace all of the standard REST endpoints with GraphQL functionality. The project I was working on had already seen me working with multiple technologies I had never used before but this one I had never...

The Argument for Training an Aging Workforce

The Argument for Training an Aging Workforce

People are choosing to work for longer for several reasons. They are living longer than previous generations. Changes to Social Security benefits, a decline in employer contributed retirement plans, along with the need to save more. They have more...

Richmond and Beyond: Becoming more Remote-Friendly

Richmond and Beyond: Becoming more Remote-Friendly

Have you ever considered remote work—either as an employee or an employer? We are. We’ve seen the momentum of companies offering remote flexibility and have heard the interest internally, but is it a viable option for us? About 90% of our team works at the...

Shockoe’s 1st Meet-Up: React Native

Shockoe’s 1st Meet-Up: React Native

The Meet-Up Overview:  Shockoe would like to provide a space for the RVA React Native community to share its knowledge and grow together. There are many options today for creating mobile applications, and React Native is a great solution for a...

eTail East: Transforming Retail. Together

eTail East: Transforming Retail. Together

We're heading back to Boston! From August 19 - August 22, Shockoe will be attending and speaking at eTail East in Boston, Massachusetts.  About eTail eTail is where the top minds in retail meet, collaborate and learn about what's disrupting the industry...