From 2dd33b16df16bc51437d7eab78741959fb450abd Mon Sep 17 00:00:00 2001 From: Jimmy Lai Date: Fri, 19 Nov 2021 07:33:22 -0800 Subject: [PATCH] add experiment for running the JS on view creation Summary: Changelog: [Internal] # Context Whilst looking at Marketplace Loom traces, ShikaSD made the remark that we could potentially start the JS work much earlier instead of waiting for the View.onMeasure call, a behaviour that is already built-in Venice. Reviewed By: ShikaSD Differential Revision: D32559505 fbshipit-source-id: cc6337955ad2b6a6581a0347f1f976679eaca54d --- .../src/main/java/com/facebook/react/ReactRootView.java | 7 ++++++- .../java/com/facebook/react/config/ReactFeatureFlags.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java index ebe012492b2e3b..fc0e891a289e65 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactRootView.java @@ -44,6 +44,7 @@ import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.common.annotations.VisibleForTesting; +import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.modules.appregistry.AppRegistry; import com.facebook.react.modules.core.DeviceEventManagerModule; import com.facebook.react.modules.deviceinfo.DeviceInfoModule; @@ -439,7 +440,11 @@ public void startReactApplication( mInitialUITemplate = initialUITemplate; mReactInstanceManager.createReactContextInBackground(); - + // if in this experiment, we initialize the root earlier in startReactApplication + // instead of waiting for the initial measure + if (ReactFeatureFlags.enableEagerRootViewAttachment) { + attachToReactInstanceManager(); + } } finally { Systrace.endSection(TRACE_TAG_REACT_JAVA_BRIDGE); } diff --git a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index c42be6e1d4effc..7e3a430e366d1a 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -80,6 +80,9 @@ public class ReactFeatureFlags { /** Feature flag to configure eager initialization of MapBuffer So file */ public static boolean enableEagerInitializeMapBufferSoFile = false; + /** Feature flag to configure eager attachment of the root view/initialisation of the JS code */ + public static boolean enableEagerRootViewAttachment = false; + private static boolean mapBufferSerializationEnabled = false; /** Enables or disables MapBuffer Serialization */