From c4a6bbc8fd8992059abdcfae2bc483bd29f31e79 Mon Sep 17 00:00:00 2001 From: Pieter De Baets Date: Thu, 11 Jul 2024 07:47:10 -0700 Subject: [PATCH] Do eager native module init on mqt_native thread (#45324) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/45324 Improve concurrency during startup of bridgeless by concurrently initializing eager native modules and triggering bundle load. Changelog: [Android][Changed] Modules marked with needsEagerInit = true will now be created on the mqt_native thread. Reviewed By: mdvacca Differential Revision: D59465977 fbshipit-source-id: 55cc0f0359bafcf32dc538f4346c6a5d5546f658 --- .../featureflags/ReactNativeFeatureFlags.kt | 8 +++- .../ReactNativeFeatureFlagsCxxAccessor.kt | 12 +++++- .../ReactNativeFeatureFlagsCxxInterop.kt | 4 +- .../ReactNativeFeatureFlagsDefaults.kt | 4 +- .../ReactNativeFeatureFlagsLocalAccessor.kt | 13 ++++++- .../ReactNativeFeatureFlagsProvider.kt | 4 +- .../facebook/react/runtime/ReactHostImpl.java | 7 ++-- .../facebook/react/runtime/ReactInstance.java | 25 ++++++++---- .../JReactNativeFeatureFlagsCxxInterop.cpp | 16 +++++++- .../JReactNativeFeatureFlagsCxxInterop.h | 5 ++- .../featureflags/ReactNativeFeatureFlags.cpp | 6 ++- .../featureflags/ReactNativeFeatureFlags.h | 7 +++- .../ReactNativeFeatureFlagsAccessor.cpp | 38 ++++++++++++++----- .../ReactNativeFeatureFlagsAccessor.h | 6 ++- .../ReactNativeFeatureFlagsDefaults.h | 6 ++- .../ReactNativeFeatureFlagsProvider.h | 3 +- .../NativeReactNativeFeatureFlags.cpp | 7 +++- .../NativeReactNativeFeatureFlags.h | 4 +- .../ReactNativeFeatureFlags.config.js | 5 +++ .../featureflags/ReactNativeFeatureFlags.js | 7 +++- .../specs/NativeReactNativeFeatureFlags.js | 3 +- 21 files changed, 151 insertions(+), 39 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt index 271245d09b6..6762d902fd6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<61e7f1b2647d1e9c9583079b5e7fb166>> + * @generated SignedSource<> */ /** @@ -142,6 +142,12 @@ public object ReactNativeFeatureFlags { @JvmStatic public fun fuseboxEnabledRelease(): Boolean = accessor.fuseboxEnabledRelease() + /** + * Construct modules that requires eager init on the dedicate native modules thread + */ + @JvmStatic + public fun initEagerTurboModulesOnNativeModulesQueueAndroid(): Boolean = accessor.initEagerTurboModulesOnNativeModulesQueueAndroid() + /** * Only enqueue Choreographer calls if there is an ongoing animation, instead of enqueueing every frame. */ diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt index 22633b10dbf..6be47b1bef0 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<> */ /** @@ -39,6 +39,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso private var forceBatchingMountItemsOnAndroidCache: Boolean? = null private var fuseboxEnabledDebugCache: Boolean? = null private var fuseboxEnabledReleaseCache: Boolean? = null + private var initEagerTurboModulesOnNativeModulesQueueAndroidCache: Boolean? = null private var lazyAnimationCallbacksCache: Boolean? = null private var setAndroidLayoutDirectionCache: Boolean? = null private var useImmediateExecutorInAndroidBridgelessCache: Boolean? = null @@ -220,6 +221,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso return cached } + override fun initEagerTurboModulesOnNativeModulesQueueAndroid(): Boolean { + var cached = initEagerTurboModulesOnNativeModulesQueueAndroidCache + if (cached == null) { + cached = ReactNativeFeatureFlagsCxxInterop.initEagerTurboModulesOnNativeModulesQueueAndroid() + initEagerTurboModulesOnNativeModulesQueueAndroidCache = cached + } + return cached + } + override fun lazyAnimationCallbacks(): Boolean { var cached = lazyAnimationCallbacksCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt index 2427763c366..0403a5cd011 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<97e3090e29645738028f11945d4b759e>> + * @generated SignedSource<<956a18f139bec734e985a48bf3265775>> */ /** @@ -66,6 +66,8 @@ public object ReactNativeFeatureFlagsCxxInterop { @DoNotStrip @JvmStatic public external fun fuseboxEnabledRelease(): Boolean + @DoNotStrip @JvmStatic public external fun initEagerTurboModulesOnNativeModulesQueueAndroid(): Boolean + @DoNotStrip @JvmStatic public external fun lazyAnimationCallbacks(): Boolean @DoNotStrip @JvmStatic public external fun setAndroidLayoutDirection(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index dbce3161165..116469104b5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<556729c01ca69ca38b51b96e6b559667>> + * @generated SignedSource<<54256999bd721723c1e7a95669311490>> */ /** @@ -61,6 +61,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi override fun fuseboxEnabledRelease(): Boolean = false + override fun initEagerTurboModulesOnNativeModulesQueueAndroid(): Boolean = false + override fun lazyAnimationCallbacks(): Boolean = false override fun setAndroidLayoutDirection(): Boolean = true diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt index c88a19c40f0..510ba531553 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<0a5ce89c1476d6693eaf18adc020ebf4>> + * @generated SignedSource<<97de4303f4682dff2e159390db982010>> */ /** @@ -43,6 +43,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces private var forceBatchingMountItemsOnAndroidCache: Boolean? = null private var fuseboxEnabledDebugCache: Boolean? = null private var fuseboxEnabledReleaseCache: Boolean? = null + private var initEagerTurboModulesOnNativeModulesQueueAndroidCache: Boolean? = null private var lazyAnimationCallbacksCache: Boolean? = null private var setAndroidLayoutDirectionCache: Boolean? = null private var useImmediateExecutorInAndroidBridgelessCache: Boolean? = null @@ -243,6 +244,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces return cached } + override fun initEagerTurboModulesOnNativeModulesQueueAndroid(): Boolean { + var cached = initEagerTurboModulesOnNativeModulesQueueAndroidCache + if (cached == null) { + cached = currentProvider.initEagerTurboModulesOnNativeModulesQueueAndroid() + accessedFeatureFlags.add("initEagerTurboModulesOnNativeModulesQueueAndroid") + initEagerTurboModulesOnNativeModulesQueueAndroidCache = cached + } + return cached + } + override fun lazyAnimationCallbacks(): Boolean { var cached = lazyAnimationCallbacksCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt index dd53c27737f..8e7d8757e1d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<16ba68de9b22ddc66208f9ef60f017d9>> + * @generated SignedSource<<60d71718bb4be3be613ffa20ea953324>> */ /** @@ -61,6 +61,8 @@ public interface ReactNativeFeatureFlagsProvider { @DoNotStrip public fun fuseboxEnabledRelease(): Boolean + @DoNotStrip public fun initEagerTurboModulesOnNativeModulesQueueAndroid(): Boolean + @DoNotStrip public fun lazyAnimationCallbacks(): Boolean @DoNotStrip public fun setAndroidLayoutDirection(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java index 80c9e0162b9..5f0432e24d4 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java @@ -1090,14 +1090,15 @@ public class ReactHostImpl implements ReactHost { getOrCreateReactHostInspectorTarget()); mReactInstance = instance; - // eagerly initailize turbo modules - instance.initializeEagerTurboModules(); - MemoryPressureListener memoryPressureListener = createMemoryPressureListener(instance); mMemoryPressureListener = memoryPressureListener; mMemoryPressureRouter.addMemoryPressureListener(memoryPressureListener); + // Eagerly initialize turbo modules in parallel with JS bundle execution + // as TurboModuleManager will handle any concurrent access + instance.initializeEagerTurboModules(); + log(method, "Loading JS Bundle"); instance.loadJSBundle(bundleLoader); diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java index 9897cbb82a4..81e81c85022 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java @@ -289,12 +289,21 @@ final class ReactInstance { } void initializeEagerTurboModules() { - Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "initializeEagerTurboModules"); - // Eagerly initialize TurboModules - for (String moduleName : mTurboModuleManager.getEagerInitModuleNames()) { - mTurboModuleManager.getModule(moduleName); + Runnable task = + () -> { + Systrace.beginSection( + Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "initializeEagerTurboModules"); + // Eagerly initialize TurboModules + for (String moduleName : mTurboModuleManager.getEagerInitModuleNames()) { + mTurboModuleManager.getModule(moduleName); + } + Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); + }; + if (ReactNativeFeatureFlags.initEagerTurboModulesOnNativeModulesQueueAndroid()) { + mQueueConfiguration.getNativeModulesQueueThread().runOnQueue(task); + } else { + task.run(); } - Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); } private static synchronized void loadLibraryIfNeeded() { @@ -309,10 +318,10 @@ final class ReactInstance { } private class ReactJsExceptionHandlerImpl implements ReactJsExceptionHandler { - private final MessageQueueThread mNativemodulesmessagequeuethread; + private final MessageQueueThread mMessageQueueThread; ReactJsExceptionHandlerImpl(MessageQueueThread nativeModulesMessageQueueThread) { - this.mNativemodulesmessagequeuethread = nativeModulesMessageQueueThread; + mMessageQueueThread = nativeModulesMessageQueueThread; } @Override @@ -320,7 +329,7 @@ final class ReactInstance { JavaOnlyMap data = StackTraceHelper.convertParsedError(error); // Simulate async native module method call - mNativemodulesmessagequeuethread.runOnQueue( + mMessageQueueThread.runOnQueue( () -> { NativeExceptionsManagerSpec exceptionsManager = (NativeExceptionsManagerSpec) diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp index ce5c6ecd6eb..cfd8a671cbb 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<0a287c69e07600efe13acfcf8bd29f0d>> */ /** @@ -153,6 +153,12 @@ class ReactNativeFeatureFlagsProviderHolder return method(javaProvider_); } + bool initEagerTurboModulesOnNativeModulesQueueAndroid() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("initEagerTurboModulesOnNativeModulesQueueAndroid"); + return method(javaProvider_); + } + bool lazyAnimationCallbacks() override { static const auto method = getReactNativeFeatureFlagsProviderJavaClass()->getMethod("lazyAnimationCallbacks"); @@ -306,6 +312,11 @@ bool JReactNativeFeatureFlagsCxxInterop::fuseboxEnabledRelease( return ReactNativeFeatureFlags::fuseboxEnabledRelease(); } +bool JReactNativeFeatureFlagsCxxInterop::initEagerTurboModulesOnNativeModulesQueueAndroid( + facebook::jni::alias_ref /*unused*/) { + return ReactNativeFeatureFlags::initEagerTurboModulesOnNativeModulesQueueAndroid(); +} + bool JReactNativeFeatureFlagsCxxInterop::lazyAnimationCallbacks( facebook::jni::alias_ref /*unused*/) { return ReactNativeFeatureFlags::lazyAnimationCallbacks(); @@ -425,6 +436,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() { makeNativeMethod( "fuseboxEnabledRelease", JReactNativeFeatureFlagsCxxInterop::fuseboxEnabledRelease), + makeNativeMethod( + "initEagerTurboModulesOnNativeModulesQueueAndroid", + JReactNativeFeatureFlagsCxxInterop::initEagerTurboModulesOnNativeModulesQueueAndroid), makeNativeMethod( "lazyAnimationCallbacks", JReactNativeFeatureFlagsCxxInterop::lazyAnimationCallbacks), diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h index 931bde58636..8390e2a4da7 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<57ee61471fc9a9d3fbcf437ec7787b98>> + * @generated SignedSource<<8bc3813da5b0d8ad6a46064b30f48ea8>> */ /** @@ -87,6 +87,9 @@ class JReactNativeFeatureFlagsCxxInterop static bool fuseboxEnabledRelease( facebook::jni::alias_ref); + static bool initEagerTurboModulesOnNativeModulesQueueAndroid( + facebook::jni::alias_ref); + static bool lazyAnimationCallbacks( facebook::jni::alias_ref); diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp index c673373affb..2260f427335 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<1f6e54fe4620719b93b97f0be257bde6>> + * @generated SignedSource<<1bea72c406359550598787ea5da29b17>> */ /** @@ -97,6 +97,10 @@ bool ReactNativeFeatureFlags::fuseboxEnabledRelease() { return getAccessor().fuseboxEnabledRelease(); } +bool ReactNativeFeatureFlags::initEagerTurboModulesOnNativeModulesQueueAndroid() { + return getAccessor().initEagerTurboModulesOnNativeModulesQueueAndroid(); +} + bool ReactNativeFeatureFlags::lazyAnimationCallbacks() { return getAccessor().lazyAnimationCallbacks(); } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h index c8fafa99615..947ec66fb80 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<52ba90db8208aec0eca2de2c9155246a>> + * @generated SignedSource<<627fb0dc656780d46131fad9bf87efa8>> */ /** @@ -132,6 +132,11 @@ class ReactNativeFeatureFlags { */ RN_EXPORT static bool fuseboxEnabledRelease(); + /** + * Construct modules that requires eager init on the dedicate native modules thread + */ + RN_EXPORT static bool initEagerTurboModulesOnNativeModulesQueueAndroid(); + /** * Only enqueue Choreographer calls if there is an ongoing animation, instead of enqueueing every frame. */ diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp index 942b33ffe7f..af1e8597449 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<0bbd53feabe770d25788128960e3ddcf>> + * @generated SignedSource<<23169873ef7f5c07f5c07f59a7440d47>> */ /** @@ -371,6 +371,24 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxEnabledRelease() { return flagValue.value(); } +bool ReactNativeFeatureFlagsAccessor::initEagerTurboModulesOnNativeModulesQueueAndroid() { + auto flagValue = initEagerTurboModulesOnNativeModulesQueueAndroid_.load(); + + if (!flagValue.has_value()) { + // This block is not exclusive but it is not necessary. + // If multiple threads try to initialize the feature flag, we would only + // be accessing the provider multiple times but the end state of this + // instance and the returned flag value would be the same. + + markFlagAsAccessed(19, "initEagerTurboModulesOnNativeModulesQueueAndroid"); + + flagValue = currentProvider_->initEagerTurboModulesOnNativeModulesQueueAndroid(); + initEagerTurboModulesOnNativeModulesQueueAndroid_ = flagValue; + } + + return flagValue.value(); +} + bool ReactNativeFeatureFlagsAccessor::lazyAnimationCallbacks() { auto flagValue = lazyAnimationCallbacks_.load(); @@ -380,7 +398,7 @@ bool ReactNativeFeatureFlagsAccessor::lazyAnimationCallbacks() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(19, "lazyAnimationCallbacks"); + markFlagAsAccessed(20, "lazyAnimationCallbacks"); flagValue = currentProvider_->lazyAnimationCallbacks(); lazyAnimationCallbacks_ = flagValue; @@ -398,7 +416,7 @@ bool ReactNativeFeatureFlagsAccessor::setAndroidLayoutDirection() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(20, "setAndroidLayoutDirection"); + markFlagAsAccessed(21, "setAndroidLayoutDirection"); flagValue = currentProvider_->setAndroidLayoutDirection(); setAndroidLayoutDirection_ = flagValue; @@ -416,7 +434,7 @@ bool ReactNativeFeatureFlagsAccessor::useImmediateExecutorInAndroidBridgeless() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(21, "useImmediateExecutorInAndroidBridgeless"); + markFlagAsAccessed(22, "useImmediateExecutorInAndroidBridgeless"); flagValue = currentProvider_->useImmediateExecutorInAndroidBridgeless(); useImmediateExecutorInAndroidBridgeless_ = flagValue; @@ -434,7 +452,7 @@ bool ReactNativeFeatureFlagsAccessor::useModernRuntimeScheduler() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(22, "useModernRuntimeScheduler"); + markFlagAsAccessed(23, "useModernRuntimeScheduler"); flagValue = currentProvider_->useModernRuntimeScheduler(); useModernRuntimeScheduler_ = flagValue; @@ -452,7 +470,7 @@ bool ReactNativeFeatureFlagsAccessor::useNativeViewConfigsInBridgelessMode() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(23, "useNativeViewConfigsInBridgelessMode"); + markFlagAsAccessed(24, "useNativeViewConfigsInBridgelessMode"); flagValue = currentProvider_->useNativeViewConfigsInBridgelessMode(); useNativeViewConfigsInBridgelessMode_ = flagValue; @@ -470,7 +488,7 @@ bool ReactNativeFeatureFlagsAccessor::useNewReactImageViewBackgroundDrawing() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(24, "useNewReactImageViewBackgroundDrawing"); + markFlagAsAccessed(25, "useNewReactImageViewBackgroundDrawing"); flagValue = currentProvider_->useNewReactImageViewBackgroundDrawing(); useNewReactImageViewBackgroundDrawing_ = flagValue; @@ -488,7 +506,7 @@ bool ReactNativeFeatureFlagsAccessor::useRuntimeShadowNodeReferenceUpdate() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(25, "useRuntimeShadowNodeReferenceUpdate"); + markFlagAsAccessed(26, "useRuntimeShadowNodeReferenceUpdate"); flagValue = currentProvider_->useRuntimeShadowNodeReferenceUpdate(); useRuntimeShadowNodeReferenceUpdate_ = flagValue; @@ -506,7 +524,7 @@ bool ReactNativeFeatureFlagsAccessor::useRuntimeShadowNodeReferenceUpdateOnLayou // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(26, "useRuntimeShadowNodeReferenceUpdateOnLayout"); + markFlagAsAccessed(27, "useRuntimeShadowNodeReferenceUpdateOnLayout"); flagValue = currentProvider_->useRuntimeShadowNodeReferenceUpdateOnLayout(); useRuntimeShadowNodeReferenceUpdateOnLayout_ = flagValue; @@ -524,7 +542,7 @@ bool ReactNativeFeatureFlagsAccessor::useStateAlignmentMechanism() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(27, "useStateAlignmentMechanism"); + markFlagAsAccessed(28, "useStateAlignmentMechanism"); flagValue = currentProvider_->useStateAlignmentMechanism(); useStateAlignmentMechanism_ = flagValue; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h index 77b01371a79..d3ed1db3de2 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<21ccc4daa6d8c02f29e4bbd4c9a75e49>> + * @generated SignedSource<> */ /** @@ -50,6 +50,7 @@ class ReactNativeFeatureFlagsAccessor { bool forceBatchingMountItemsOnAndroid(); bool fuseboxEnabledDebug(); bool fuseboxEnabledRelease(); + bool initEagerTurboModulesOnNativeModulesQueueAndroid(); bool lazyAnimationCallbacks(); bool setAndroidLayoutDirection(); bool useImmediateExecutorInAndroidBridgeless(); @@ -69,7 +70,7 @@ class ReactNativeFeatureFlagsAccessor { std::unique_ptr currentProvider_; bool wasOverridden_; - std::array, 28> accessedFeatureFlags_; + std::array, 29> accessedFeatureFlags_; std::atomic> commonTestFlag_; std::atomic> allowCollapsableChildren_; @@ -90,6 +91,7 @@ class ReactNativeFeatureFlagsAccessor { std::atomic> forceBatchingMountItemsOnAndroid_; std::atomic> fuseboxEnabledDebug_; std::atomic> fuseboxEnabledRelease_; + std::atomic> initEagerTurboModulesOnNativeModulesQueueAndroid_; std::atomic> lazyAnimationCallbacks_; std::atomic> setAndroidLayoutDirection_; std::atomic> useImmediateExecutorInAndroidBridgeless_; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index 93c8cc64a9b..6b5e88cc077 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<1f576108717e5bd1b5ca8de0aaae5b0e>> + * @generated SignedSource<<031622096a93ca9da5e278dab84324b9>> */ /** @@ -103,6 +103,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { return false; } + bool initEagerTurboModulesOnNativeModulesQueueAndroid() override { + return false; + } + bool lazyAnimationCallbacks() override { return false; } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h index 4648b0b5c43..6b6c1c2cffb 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<760ad06ff565102e3ba42d671f45a470>> + * @generated SignedSource<<55e4299def48d95ea40cd988e70fd608>> */ /** @@ -44,6 +44,7 @@ class ReactNativeFeatureFlagsProvider { virtual bool forceBatchingMountItemsOnAndroid() = 0; virtual bool fuseboxEnabledDebug() = 0; virtual bool fuseboxEnabledRelease() = 0; + virtual bool initEagerTurboModulesOnNativeModulesQueueAndroid() = 0; virtual bool lazyAnimationCallbacks() = 0; virtual bool setAndroidLayoutDirection() = 0; virtual bool useImmediateExecutorInAndroidBridgeless() = 0; diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index fcefaf0f494..944e9ef00a1 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<1c3b8179bf67dd9d44c8d2e29bf752b6>> + * @generated SignedSource<<345d27de837a248fbfd5e299754097f0>> */ /** @@ -132,6 +132,11 @@ bool NativeReactNativeFeatureFlags::fuseboxEnabledRelease( return ReactNativeFeatureFlags::fuseboxEnabledRelease(); } +bool NativeReactNativeFeatureFlags::initEagerTurboModulesOnNativeModulesQueueAndroid( + jsi::Runtime& /*runtime*/) { + return ReactNativeFeatureFlags::initEagerTurboModulesOnNativeModulesQueueAndroid(); +} + bool NativeReactNativeFeatureFlags::lazyAnimationCallbacks( jsi::Runtime& /*runtime*/) { return ReactNativeFeatureFlags::lazyAnimationCallbacks(); diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index b5df7b0e290..ea92618e04c 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<> + * @generated SignedSource<<4121c9b419a41e84ec2c1066cb2707e2>> */ /** @@ -73,6 +73,8 @@ class NativeReactNativeFeatureFlags bool fuseboxEnabledRelease(jsi::Runtime& runtime); + bool initEagerTurboModulesOnNativeModulesQueueAndroid(jsi::Runtime& runtime); + bool lazyAnimationCallbacks(jsi::Runtime& runtime); bool setAndroidLayoutDirection(jsi::Runtime& runtime); diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index 662fea1331d..da677636559 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -128,6 +128,11 @@ const definitions: FeatureFlagDefinitions = { description: 'Flag determining if the React Native DevTools (Fusebox) CDP backend should be enabled in release builds. This flag is global and should not be changed across React Host lifetimes.', }, + initEagerTurboModulesOnNativeModulesQueueAndroid: { + defaultValue: false, + description: + 'Construct modules that requires eager init on the dedicate native modules thread', + }, lazyAnimationCallbacks: { defaultValue: false, description: diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 606bbae4a93..3fd57ddfddb 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<3fce773b88616a376b8ab6dbd5649813>> + * @generated SignedSource<<3ee4e03eae552b81423262351ee2a494>> * @flow strict-local */ @@ -60,6 +60,7 @@ export type ReactNativeFeatureFlags = { forceBatchingMountItemsOnAndroid: Getter, fuseboxEnabledDebug: Getter, fuseboxEnabledRelease: Getter, + initEagerTurboModulesOnNativeModulesQueueAndroid: Getter, lazyAnimationCallbacks: Getter, setAndroidLayoutDirection: Getter, useImmediateExecutorInAndroidBridgeless: Getter, @@ -192,6 +193,10 @@ export const fuseboxEnabledDebug: Getter = createNativeFlagGetter('fuse * Flag determining if the React Native DevTools (Fusebox) CDP backend should be enabled in release builds. This flag is global and should not be changed across React Host lifetimes. */ export const fuseboxEnabledRelease: Getter = createNativeFlagGetter('fuseboxEnabledRelease', false); +/** + * Construct modules that requires eager init on the dedicate native modules thread + */ +export const initEagerTurboModulesOnNativeModulesQueueAndroid: Getter = createNativeFlagGetter('initEagerTurboModulesOnNativeModulesQueueAndroid', false); /** * Only enqueue Choreographer calls if there is an ongoing animation, instead of enqueueing every frame. */ diff --git a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js index 02b380e8395..134f984574f 100644 --- a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js @@ -4,7 +4,7 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * - * @generated SignedSource<<4f001bdc6d2161ead95635785f387abe>> + * @generated SignedSource<<44f6fe8269f1b8d2039668e67bca9839>> * @flow strict-local */ @@ -42,6 +42,7 @@ export interface Spec extends TurboModule { +forceBatchingMountItemsOnAndroid?: () => boolean; +fuseboxEnabledDebug?: () => boolean; +fuseboxEnabledRelease?: () => boolean; + +initEagerTurboModulesOnNativeModulesQueueAndroid?: () => boolean; +lazyAnimationCallbacks?: () => boolean; +setAndroidLayoutDirection?: () => boolean; +useImmediateExecutorInAndroidBridgeless?: () => boolean;