From 58409be6b47d58d2f9497912ff001e13f7dff4b6 Mon Sep 17 00:00:00 2001 From: Peter Argany Date: Tue, 28 Aug 2018 10:58:24 -0700 Subject: [PATCH] Eagerly create FBMarketplaceNativeModule [2/N] Summary: The full idea for eagerly creating Native Modules is articulated here https://fb.quip.com/vWcLAup3a6kR TLDR: 1) Move lazy native module work from the mqt_js thread to the background thread which processes packages. This also moves it from post-network to pre-network. 2) For a quick test, decide which modules to eagerly create with a QE flag. 3) Eagerly create the modules by opting-out of the ReactModuleInfo pipeline which was built for lazy native modules. Reviewed By: achen1 Differential Revision: D9503934 fbshipit-source-id: 0cd8337ad294cd0f8be692fecbf4292d204f3ec4 --- .../main/java/com/facebook/react/LazyReactPackage.java | 8 ++++++++ .../com/facebook/react/NativeModuleRegistryBuilder.java | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java b/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java index e9b29db7c..8f15a7f63 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java +++ b/ReactAndroid/src/main/java/com/facebook/react/LazyReactPackage.java @@ -96,6 +96,14 @@ public abstract class LazyReactPackage implements ReactPackage { return modules; } + /** + * @return list of native modules which should be eagerly initialized. + */ + public List getEagerNativeModules() { + return Collections.emptyList(); + } + + /** * @param reactContext react application context that can be used to create View Managers. * @return list of module specs that can create the View Managers. diff --git a/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java index ba107f1a6..2c6877902 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/NativeModuleRegistryBuilder.java @@ -45,6 +45,7 @@ public class NativeModuleRegistryBuilder { if (reactPackage instanceof LazyReactPackage) { LazyReactPackage lazyReactPackage = (LazyReactPackage) reactPackage; List moduleSpecs = lazyReactPackage.getNativeModules(mReactApplicationContext); + List eagerNativeModules = lazyReactPackage.getEagerNativeModules(); Map reactModuleInfoMap = lazyReactPackage.getReactModuleInfoProvider().getReactModuleInfos(); @@ -52,7 +53,7 @@ public class NativeModuleRegistryBuilder { String className = moduleSpec.getClassName(); ReactModuleInfo reactModuleInfo = reactModuleInfoMap.get(className); ModuleHolder moduleHolder; - if (reactModuleInfo == null) { + if (reactModuleInfo == null || eagerNativeModules.contains(className)) { NativeModule module; ReactMarker.logMarker( ReactMarkerConstants.CREATE_MODULE_START,