Integrating and Evaluating the Hermes JavaScript Engine in React Native Android Projects
This article introduces Facebook's Hermes JavaScript engine, details its integration into React Native Android projects, explains its bytecode precompilation and JIT‑free design, presents performance benchmarks versus JavaScriptCore and V8, and discusses current limitations and future considerations.
Facebook announced the Hermes JavaScript engine at ChainReact 2019, a lightweight engine optimized for Android React Native. The authors quickly integrated Hermes into the Ctrip CRN project and began a deep performance investigation.
Hermes improves three key metrics compared with JavaScriptCore: Time‑to‑Interact drops from 4.3 s to 2.01 s, app download size shrinks from 41 MB to 22 MB, and memory usage falls from 185 MB to 136 MB.
Quick start with hermesvm :
// 创建hermes_test文件,内容:print("This is Hermes Demo");
vim hermes_test.js
// 直接执行纯文本js
~
/node_modules/
hermesvm/osx-bin/hermes hermes_test.js
This is Hermes Demo
// 转换成bytecode
~
/node_modules/
hermesvm/osx-bin/hermes --emit-binary hermes_test.js -out hermes_test.hbc
// 执行字节码
~
/node_modules/
hermesvm/osx-bin/hermes hermes_test.hbc
This is Hermes DemoHermes achieves its gains through two main optimizations: (1) Bytecode pre‑compilation – the engine generates bytecode at build time, eliminating runtime parsing overhead; (2) Dropping JIT – avoiding just‑in‑time compilation reduces startup latency and memory footprint, though pure‑text JS runs slower than JSC.
Integration steps include enabling Hermes in android/app/build.gradle (setting enableHermes: true ), rebuilding the project, and optionally converting the JS bundle to bytecode with the hermes --emit-binary command. The build process adds a post‑bundle step that runs Hermes on the generated bundle.
Performance comparison among Hermes, JavaScriptCore, and V8 shows that Hermes delivers faster first‑screen rendering (≈15 % improvement over JSC in Ctrip’s ticket module), reduces native .so size by ~16 %, and exhibits smoother memory and CPU usage patterns. V8 performs poorly in these mobile scenarios.
Current challenges include the large size of Hermes bytecode files (up to 100 % larger than plain JS), slower execution of pure‑text JS due to the lack of JIT, and sub‑optimal caching behavior where a cached Hermes engine can be slower than a fresh start. The team mitigates the bytecode size issue by compiling bytecode on‑device when possible and falling back to JSC otherwise.
In conclusion, while Hermes offers significant performance benefits, unresolved cache stability and bytecode size concerns prevent immediate production rollout. The authors suggest a hybrid approach—using JSC for pure‑text JS and switching to Hermes after bytecode conversion—while continuing to evaluate stability and compatibility.
Ctrip Technology
Official Ctrip Technology account, sharing and discussing growth.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.