DEV Community

Bojie Liu
Bojie Liu

Posted on

Easily Use QuickJS In React Native

What Is QuickJS

QuickJS is a small and embeddable Javascript engine. It supports the ES2020 specification including modules, asynchronous generators, proxies and BigInt. More features can be found here.

Why would I choose QuickJS for React Native

Based on the performance results on large-scale real-world react-native application and its main features. QuickJS is suitable for some scenarios and not for the others. Besides my humble opinions as follows, you could try using QuickJS to run javascript in ReactNative yourself by adding a few lines of codes in your application to see the results in your cases.

  1. On Android, QuickJS is slower than V8 in most of my tests. Although it has advantages in memory and binary size which is important on some resource-limited devices. Also QuickJS is benefit from its startup time for some simple bundles.
  2. On iOS, QuickJS simply better than JSC with code cache and worst than JSC without code cache.
  3. QuickJS is easy to customize when it compared with V8 or Hermes. Like adding some high performance builtin functions or customized classes. It depends on your business.
  4. Currently QuickJS have no inspector. But it seems some open source projects have made it worked. Anyway it needs extra works to support inspector in the future.

Performance Result

Real world bundle performance

  1. We tested QuickJS/V8/JSC with an online bundle size of 1.43M.
  2. On Android, we enabled code cache for both QuickJS and V8. For TTI, QuickJS is 5-20% slower than V8. For PSS memory, QuickJS is 40-(-5)% lower than V8.
  3. On iOS, TTI using QuickJS is 15% slower than JSC without code cache. With code cache, QuickJS is 15% faster than JSC and 50% lower than JSC in footprint memory usage.

ESx Compatibility

As listed on official QuickJS website. QuickJS passed 82% of ECMA-262 tests. Meanwhile V8 passed 86% and JSC passed 85% in 2022. If internationalization tests which accounts for nearly 3% are excluded, QuickJS is fairly close to V8 and JSC. You can checkout https://test262.report/ for failed cases just in case.

Github

If there are any further questions, welcome to communicate at https://github.com/bojie-liu/react-native-quickjs.

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs