From 052e578ed666f2749ec06d1d928bb622cada8841 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Fri, 6 Nov 2020 00:30:56 -0800 Subject: [PATCH] Set up experiment to dispatch promise methods asynchronously to NativeModules thread Summary: TurboModule methods that return promises are synchronously run on the JavaScript thread. Back in D22489338 (https://github.com/facebook/react-native/commit/9c35b5b8c4710dfe6a4b689a5565aa78ae5b37d3), we wrote code to make them dispatch on the NativeModules thread. That code, however, was just left disabled. In this diff, I wire up the TurboModules infra to a MobileConfig, which should allow us to assess the performance impact of async dispatch of promise methods to the NativeModules thread in production, before we roll it out more widely. Changelog: [Internal] Reviewed By: fkgozali Differential Revision: D24685389 fbshipit-source-id: 8ceb2e6effc125abecfa76e5e90bd310676aefc9 --- .../main/java/com/facebook/react/config/ReactFeatureFlags.java | 3 +++ .../facebook/react/turbomodule/core/TurboModuleManager.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) 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 04a8a88eb5ca6d..9d8f1c4859a0d8 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -23,6 +23,9 @@ public class ReactFeatureFlags { */ public static volatile boolean useTurboModules = false; + /** Should we dispatch TurboModule methods with promise returns to the NativeModules thread? */ + public static volatile boolean enableTurboModulePromiseAsyncDispatch = false; + /* * This feature flag enables logs for Fabric */ diff --git a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java index e6e6fcce69e099..8303d153f618db 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/turbomodule/core/TurboModuleManager.java @@ -17,6 +17,7 @@ import com.facebook.react.bridge.JSIModule; import com.facebook.react.bridge.JavaScriptContextHolder; import com.facebook.react.bridge.NativeModule; +import com.facebook.react.config.ReactFeatureFlags; import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder; import com.facebook.react.turbomodule.core.interfaces.TurboModule; import com.facebook.react.turbomodule.core.interfaces.TurboModuleRegistry; @@ -60,7 +61,7 @@ public TurboModuleManager( (CallInvokerHolderImpl) jsCallInvokerHolder, (CallInvokerHolderImpl) nativeCallInvokerHolder, delegate, - false); + ReactFeatureFlags.enableTurboModulePromiseAsyncDispatch); installJSIBindings(); mEagerInitModuleNames =