npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-v8

v2.5.1

Published

Opt-in V8 runtime for React Native Android

Downloads

19,199

Readme

npm version Build for Android

React Native with V8 Runtime

This project aims to support V8 replacement runtime for React Native. Designed as opt-in package, it is easy to integrate with existing React Native projects.

Note From react-native-v8 2.0, the minimum requirement for react-native is 0.71.2.

For earlier versions, please check out the older readmes.

Installation for Expo projects (>= SDK 48)

For managed projects, you can install through the single command:

$ npx expo install react-native-v8 v8-android-jit

For bare projects, you can run npx expo prebuild -p android --clean after the installation to prebuild again.

Installation for React Native >= 0.71

  1. Install react-native-v8 and a v8-android variant. For example, the v8-android-jit:
$ yarn add react-native-v8 v8-android-jit
  1. Exclude unused libraries to reduce APK size
--- a/android/app/build.gradle
+++ b/android/app/build.gradle
@@ -161,11 +161,18 @@ android {
             }
         }
     }
+
+    packagingOptions {
+        // Make sure libjsc.so does not packed in APK
+        exclude "**/libjsc.so"
+    }
 }
  1. Setup V8 in the MainApplication.java.
--- a/android/app/src/main/java/com/rn071/MainApplication.java
+++ b/android/app/src/main/java/com/rn071/MainApplication.java
@@ -1,15 +1,20 @@
 package com.rn071;

 import android.app.Application;
+
 import com.facebook.react.PackageList;
 import com.facebook.react.ReactApplication;
 import com.facebook.react.ReactNativeHost;
 import com.facebook.react.ReactPackage;
+import com.facebook.react.bridge.JavaScriptExecutorFactory;
 import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
 import com.facebook.react.defaults.DefaultReactNativeHost;
+import com.facebook.react.modules.systeminfo.AndroidInfoHelpers;
 import com.facebook.soloader.SoLoader;
 import java.util.List;

+import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;
+
 public class MainApplication extends Application implements ReactApplication {

   private final ReactNativeHost mReactNativeHost =
@@ -42,6 +47,15 @@ public class MainApplication extends Application implements ReactApplication {
         protected Boolean isHermesEnabled() {
           return BuildConfig.IS_HERMES_ENABLED;
         }
+
+        @Override
+        protected JavaScriptExecutorFactory getJavaScriptExecutorFactory() {
+          return new V8ExecutorFactory(
+              getApplicationContext(),
+              getPackageName(),
+              AndroidInfoHelpers.getFriendlyDeviceName(),
+              getUseDeveloperSupport());
+        }
       };

   @Override

For React Native 0.73 and above, you can use the following code instead:

--- a/android/app/src/main/java/com/rn073/MainApplication.kt
+++ b/android/app/src/main/java/com/rn073/MainApplication.kt
@@ -1,15 +1,20 @@
 package com.rn073;

 import android.app.Application
+
 import com.facebook.react.PackageList
 import com.facebook.react.ReactApplication
 import com.facebook.react.ReactHost
 import com.facebook.react.ReactNativeHost
 import com.facebook.react.ReactPackage
+import com.facebook.react.bridge.JavaScriptExecutorFactory
 import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
 import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
 import com.facebook.react.defaults.DefaultReactNativeHost
 import com.facebook.react.flipper.ReactNativeFlipper
+import com.facebook.react.modules.systeminfo.AndroidInfoHelpers
 import com.facebook.soloader.SoLoader

+import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory;
+
 class MainApplication : Application(), ReactApplication {

   override val reactNativeHost: ReactNativeHost =
      object : DefaultReactNativeHost(this) {
        override fun getPackages(): List<ReactPackage> =
            PackageList(this).packages.apply {
              // Packages that cannot be auto linked yet can be added manually here, for example:
              // add(MyReactNativePackage())
            }
        override fun getJSMainModuleName(): String = "index"

        override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG

        override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
        override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
+
+       override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory =
+            V8ExecutorFactory(
+                applicationContext,
+                packageName,
+                AndroidInfoHelpers.getFriendlyDeviceName(),
+                useDeveloperSupport
+            )
       };

    override val reactHost: ReactHost
  1. Disable Hermes
--- a/android/gradle.properties
+++ b/android/gradle.properties
@@ -41,4 +41,4 @@ newArchEnabled=false

 # Use this property to enable or disable the Hermes JS engine.
 # If set to false, you will be using JSC instead.
-hermesEnabled=true
+hermesEnabled=false
  1. yarn android

  2. You can verify whether it works by evaluating the global._v8runtime().version JavaScript statement.

Builtin JavaScript object

global._v8runtime() has some builtin information such as v8 version.

console.log(`V8 version is ${global._v8runtime().version}`);

Please note that global._v8runtime() existed only for V8 enabled environment but not React Native remote debugging mode. For remote debugging mode, the JavaScript actually runs on Chrome from your host and there is no V8Runtime.

V8 Variants

react-native-v8 depends on a V8 shared library built from v8-android-buildscripts. v8-android-jit is the recommended V8 variant. This is a full featured V8 with both JIT and Intl. We provide other V8 variants to fulfill your needs. For instance, if you want to reduce memory usage, the non JIT variant, aka V8 lite mode. For detailed V8 features, please check the v8-android-buildscripts feature flags.

| Package name | JIT | Intl | | ----------------------- | --- | ---- | | v8-android-jit | Yes | Yes | | v8-android-jit-nointl | Yes | No | | v8-android | No | Yes | | v8-android-nointl | No | No |

iOS Support (Experimental)

You could try the experimental ios support on an Expo project which SDK version is greater or equal to 48.

For managed projects, you can install through the single command:

$ npx expo install react-native-v8 v8-ios

For bare projects, you can run npx expo prebuild -p ios --clean after the installation to prebuild again.

FAQ

How to reduce APK size ?

The V8 currently bundled by default supports Intl and the ICU data costs about 7MiB per ABI. If you are not going to use Intl, you could use no-Intl version to reduce APK size. (jsc-android have no Intl by default)

TODO

  • [x] Performance comparison with JavaScriptCore in React Native

    Please check https://github.com/Kudo/react-native-js-benchmark for the benchmark and result

  • [x] V8 inspector integration

  • [ ] V8 snapshot integration

  • [ ] V8 code cache experiment