How Facebook Boosted React Native with JS

Mobile apps are flooding the market right now, and there’s an army of devs behind this force. While they can choose among dozens of development tools, some frameworks are more demanded than others.

If you have ever googled React Native services, you should know something about the framework itself. In this guide, however, we will cover the basics of React Native and the improvements it has undergone. Namely, we will focus on Hermes — a custom JavaScript engine developed by Facebook to optimize the reviewed framework.

About React Native

react native 2
The framework was designed by Facebook back in 2015. Mainly, it is used by Android and iOS developers. Before the launch, Mark Zuckerberg noted that his biggest mistake in Facebook was relying too heavily on HTML. Three years after this speech, React Native was released to provide better native development experience.

Technically, React Native is similar to its big brother React. However, instead of using the virtual DOM, it enables end-device background processes. This helps to effectively connect to native platforms. Also, React Native doesn’t work with HTML or CSS, but instead, uses JavaScript. Developers can create native apps for Android using Java and for iOS using Swift or Objective-C. Overall, the tool looks pretty convenient and smooth.

About Hermes

react native 3
But Facebook wanted to improve it further. In 2019, the company released a special JS engine called Hermes. It’s an open-source solution designed for better performance of Android-based applications.

Architectural Basics

 

To understand how Facebook boosts React Native via Hermes, check three architectural changes for this tool.

  1. Lack of JITs. Firstly, Facebook decided to get rid of the just-in-time inventory or JITs. Developers noted that this solution didn’t give the needed performance results in benchmarks. As well, JITs negatively affected all critical parameters: TTI, memory usage, and size. Instead, the creators focused on improving interpreter tools.
  2. Pre-compilation of the bytecode. Hermes utilizes a custom compiler that runs in parallel with the building procedures. This makes the bytecode smaller. It can be loaded when needed and interpreted without moving through the entire file. Also, the engine code is small too.
  3. Garbage collecting processes. To avoid the app’s long restarts, Facebook built a custom garbage-collecting module. It has an on-demand allocation, supports moving objects, and doesn’t drain resources. Mainly, the solution relies on the optimized processing of virtual addresses in apps.

Key Features and Benefits

react native 4
Well, but what about the key functionality of Hermes? It is now clear that the engine improves performance greatly but it’s always better to try on your own. Before using the solution, be sure to analyze its core features:

  • Complex optimization opportunity;
  • Convenient packaging of JavaScript strings;
  • De-duplication of identical functions;
  • ECMAScript 2015 standards;
  • Memory-mapping and flash loading for bytecode;
  • Minimum overhead and garbage collection pauses;
  • Parsing and compiling simultaneously with building;
  • Small size of Android APK files;
  • Virtual addresses in chunks.

Potential Limitations

Although many large companies like Facebook, Walmart, and Bloomberg put React Native to good use, this framework remains inconvenient to some extent. Developers still have to integrate parts of native code and React Native components to use the required functions.

When it comes to Hermes limitations, the solution is designed for mobile development exclusively. Facebook doesn’t plan to extend its functionality to web applications. Thus, you should consider other solutions for web-based projects — for instance, Node.js. Apart from these two disadvantages, the combination of React Native and Hermes works pretty effectively.

Boosting Your Apps Even More

react native 5
What if this tool isn’t enough to boost the performance of apps? Below, we have provided the ultimate list of tips and tricks. Move through it to find useful strategies, mobile development secrets, and common best practices.

  • Avoid multitasking and focus on single threads;
  • Boost TTI, avoid using ObjectFinalize elements;
  • Combat memory leaks by utilizing scrolling lists;
  • Enhance UI elements, for example, sync rendering, and render only the needed parts;
  • Get rid of extra rendering by checking elements with ShouldComponentUpdate;
  • Improve navigation features with relevant components;
  • Make JSON simpler because complex objects may slow down your app significantly;
  • Minimize cache requests by setting low duration for frequent updates and vice versa;
  • Optimize screen orientation with native navigation and root views;
  • Reduce the apps’ size through graphics, components, and command line;
  • Upgrade the framework to get better performance;
  • Use visual elements efficiently by choosing the right formats like PNG or WebP.

Conclusion

react native 6
Combined with React Native, Hermes significantly improves Android JavaScript development and user experience. This engine improves the performance of applications in several core areas, including size and speed. While Hermes features a few limitations, it can be a viable tool. As long as Facebook includes this engine in the main React Native package, you can try it at any time without issues.