Bringing Hermes to iOS in React Native 0.64
Tags: reactnative, ios
Published: 2021-05-12 13:27:53

For a long time [Hermes was exclusive to Android](https://callstack.com/blog/optimize-android-app-startup-time-with-hermes/?utm_campaign=Hermes_MB&utm_source=dev.to&utm_medium=article&utm_content=Hermes_android_optimization) – it was optimized for running React Native apps on Android only. Now it’s finally **available on iOS as well.**

In the last few months, we’ve worked really hard with teams at Facebook and Microsoft to bring Hermes to iOS. It’s part of the [latest React Native 0.64 release](https://github.com/facebook/react-native/releases) which we contributed to.

{% twitter 1370505661658857472 %}

Today we’d like to share with you the steps we took here, at Callstack, to make it all possible. We also have a series of benchmarks ready to better demonstrate Hermes performance compared to JSC in the context of React Native.

**In order to outline the journey to Hermes iOS comprehensively, we are going to publish a series of articles:**

- Bringing Hermes to iOS in React Native 0.64 (you are here)
- [Hermes Performance on iOS: How it Compares with JSC](https://callstack.com/blog/hermes-performance-on-ios/?utm_campaign=Hermes_MB&utm_source=dev.to&utm_medium=article&utm_content=hermes_performance_on_ios)
- Technical Guide, Part 1: Compiling Hermes for Apple Platforms
- Technical Guide, Part 2: Integrating Hermes with React Native

The technical pieces will focus on implementation details, guiding you through the internals of React Native and showing how we brought Hermes to iOS as well as how you can use your own custom engine yourself! 

But first things first – let’s start with talking about the beginnings of the Hermes engine.

##JavaScript engine in a React Native app
Hermes is a JavaScript engine, so let’s clarify first what JS engines do. A JavaScript engine runs your application code and makes the browser perform the desired actions.

All modern JS engines are designed and benchmarked to run with maximum efficiency under the browsers’ most popular use case (i.e. providing an interactive website or a web application that users can interact with).

React Native apps, despite being written in JavaScript, are different from a typical website or a web application created with React. They use neither HTML nor CSS. Instead of interacting with DOM, when [building apps with React Native](https://callstack.com/react-native-mobile-apps?utm_campaign=Hermes_MB&utm_source=dev.to&utm_medium=service_subpage&utm_content=rn_mobile_app_development_subpage), a native code is shipped for both iOS and Android, respectively. The code is responsible for painting elements on a mobile screen and responding to the user’s interactions.

![abstract concept of user experience with Hermes on iOS](https://static.callstack.com/wp/2021/04/12153603/hermes-illustrations-new_graf1-700x405.png "abstract concept of user experience with Hermes on iOS")

##User expectations for mobile and web
There’s also a difference in the way users expect mobile and web applications to work. On mobile, the user tends to be more demanding when it comes to overall performance. Applications must launch in a blink of an eye and become interactive as quickly as possible. The web, on the other hand, is a different story. The conversion is less likely to drop if a website doesn’t load instantly.

It’s no surprise then that using a JavaScript engine designed for the web makes it harder (if not impossible in certain scenarios) to meet the high standard in the mobile world – the standards that fully-native applications often reach by default.

##Benefits of Hermes running on Android
That’s one of the many reasons why the Facebook team created Hermes – a JavaScript engine designed specifically for running React Native applications. At a high level, it is an engine like any other. Under the hood, it implements a lot of [optimizations](https://callstack.com/blog/the-ultimate-guide-to-react-native-optimization/?utm_campaign=Hermes_MB&utm_source=dev.to&utm_medium=ebook&utm_content=react_native_performance_optimization_guide) to make React Native run as fast as it can.

The biggest difference is that Hermes is an AOT engine. In other words, unlike most JavaScript engines, it doesn’t parse and compile your JavaScript code at runtime. It shifts all these steps to happen at a build time – when you bundle your React Native application before sending to the App Store.

![data concerning Hermes on Android](https://static.callstack.com/wp/2021/04/12153825/hermes-illustrations-new_table-1-1-700x405.png "data concerning Hermes on Android")Data source:[Facebook engineers](https://engineering.fb.com/2019/07/12/android/hermes/)

Since its launch on Android, the results are remarkable! It not only offers a smooth transition for the majority of users, but also provides significant improvements to startup times together with CPU and memory consumption. For a more [detailed description of Hermes on Android](https://engineering.fb.com/2019/07/12/android/hermes/), check the Facebook Engineers blog.

Please keep in mind that the numbers shown in the graph are relevant for Android only and as such they do not guarantee the same improvements on iOS. In fact, as we learn in the next section, it is possible that things like an application size can actually increase a bit.

##Bringing Hermes to iOS
Having the same JavaScript engine on both Android and iOS allows us to fully embrace its features. It also makes the development easier and provides a more stable experience with resolving less platform-specific issues.

Ever since the first React Native release, both platforms used JavaScriptCore – the one and only engine on iOS that was set to be used on Android as well. Theoretically, Android could have used V8 or a different engine, but that would contradict my previous point.

Now that Android has Hermes support and that’s been getting more and more popular with every React Native release, it would be great to have it on iOS as well. Only when Hermes can be run on both iOS and Android, the React Native team can take advantage of its features and start embracing its full potential.

###Potential risks
The JavaScriptCore wasn’t selected as a default engine for a reason. On Apple devices, it is prohibited to ship mobile applications that run JavaScript using a different JIT engine than the one originally provided with the system.

Since Hermes is an AOT engine, these restrictions do not apply. Theoretically, it is possible to build and ship apps with Hermes provided that the Hermes engine can compile on iOS. 

However, choosing a different engine than the built-in one, has the risk of increasing the overall application size as now it has to ship its own engine rather than rely on the one available on iOS by default.

##Try Hermes yourself
Hermes is now available under a flag on iOS, starting from React Native 0.64. Check out [our post on the official React Native blog](https://reactnative.dev/blog/2021/03/12/version-0.64) to find out how to turn it on! I am really excited to see what you end up building on top of it!

In case you are still having doubts about using Hermes with React Native on iOS, worry not – we have run a [series of benchmarks comparing Hermes and JSC on iOS](https://callstack.com/blog/hermes-performance-on-ios/?utm_campaign=Hermes_MB&utm_source=dev.to&utm_medium=article&utm_content=hermes_performance_on_ios) together with metrics and videos. Here’s a little secret – it’s faster!