1. What is the Hermes engine and what are its advantages?
First things first: The Hermes engine is a JavaScript engine developed by Facebook to replace JavaScript Core on the React-Native Android side. The Hermes engine has the advantage of being a lightweight JavaScript engine for mobile devices. Aot compilation reduces memory usage on Android devices, reduces installation package size, and improves execution efficiency.
What is a JavaScript engine?
A JavaScript engine is a virtual machine that specializes in JavaScript scripting and is typically shipped with a web browser.
3. Mainstream JavaScript engines
V8 (Google), JavaScriptCore (Apple), And SpiderMonkey (Firefox)
4. JavaScript engine in RN
Weex, Android: V8, iOS: JavaScriptCore
RN, Android: JavaScriptCore (Hermes, V8), iOS: JavaScriptCore (Apple required)
Note: Hermes Engine is supported with react-Native 0.60.2 release
5. The character of Hermes
-
Precompiled bytecode (the engine loads binaries more efficiently than it runs JS scripts)
-
No JIT compiler (reduced engine size, optimized memory footprint, but worse performance than V8 and JSC running JS scripts directly)
-
Garbage collection strategy for mobile
6. Optimization principle
7. Existing projects are connected to Hermes
-
Upgrade React-Native and related libraries (low cost)
-
Since react-Native 0.60.x is changed to rely on AndroidX, the Android project needs to use version 28 or higher to compile, adapt to higher Android versions, and need to migrate to AndroidX (high cost).
-
Modify build.gradle to add Hermes properties and dependencies (less cost)
8. Is CodePush supported?
Release way | Whether to support | note |
code-push release-react
|
Supported, but cannot produce precompiled script artifacts
|
You need to rely on the react-native bundle command to package scripts. This command does not support precompilation
|
code-push release
|
support
|
9. Debugging efficiency
10.ES standard support
11. Performance research
Package size analysis
The package size is reduced by 2MB for an overall reduction of 2MB / 20MB = 10%
Memory Analysis
▍ TTI performance
In React-Native Android, it is mainly the time from the start of Application onCreate to the completion of RN component rendering for interaction.
It is worth teasing that the iOS version of Pref Monitor directly includes the display of this indicator, but the Android version of Pref Monitor only has four indicators and does not have TTI indicators.
The original package TTI 829 ms
TTI decreased by 135ms, and overall decreased by 135ms / 829ms = 16%
12. To summarize
This article is first sent from Pratt & Whitney Travel Product Technology (ID: PZCXtech)