Skip to content

Commit f8f7949

Browse files
rubennortefacebook-github-bot
authored andcommitted
Move feature flags for the event loop to ReactNativeFeatureFlags (re-land) (#42677)
Summary: Pull Request resolved: #42677 Changelog: [internal] This is a re-application of #42434 which had to be reverted after a problem in a previous PR. See details in the original PR. Reviewed By: huntie Differential Revision: D53122991 fbshipit-source-id: 5bc4306522fc5fa48ea81d0802d0f891706cfbf5
1 parent 5e66f41 commit f8f7949

File tree

46 files changed

+388
-150
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+388
-150
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,6 @@ public class com/facebook/react/config/ReactFeatureFlags {
19171917
public static field unstable_useFabricInterop Z
19181918
public static field unstable_useTurboModuleInterop Z
19191919
public static field unstable_useTurboModuleInteropForAllTurboModules Z
1920-
public static field useModernRuntimeScheduler Z
19211920
public static field useNativeViewConfigsInBridgelessMode Z
19221921
public static field useTurboModules Z
19231922
public fun <init> ()V

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,6 @@ public class ReactFeatureFlags {
127127
/** When enabled, rawProps in Props will not include Yoga specific props. */
128128
public static boolean excludeYogaFromRawProps = false;
129129

130-
/**
131-
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with
132-
* priorities from any thread.
133-
*/
134-
public static boolean useModernRuntimeScheduler = false;
135-
136130
/**
137131
* Enables storing js caller stack when creating promise in native module. This is useful in case
138132
* of Promise rejection and tracing the cause.

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c201b2b577ab4aa4bf6071d6b99b43c9>>
7+
* @generated SignedSource<<52367278b4d0fdf7f436bd8c511d4ffe>>
88
*/
99

1010
/**
@@ -33,6 +33,21 @@ object ReactNativeFeatureFlags {
3333
*/
3434
fun commonTestFlag() = accessor.commonTestFlag()
3535

36+
/**
37+
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.
38+
*/
39+
fun useModernRuntimeScheduler() = accessor.useModernRuntimeScheduler()
40+
41+
/**
42+
* Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).
43+
*/
44+
fun enableMicrotasks() = accessor.enableMicrotasks()
45+
46+
/**
47+
* When enabled, the RuntimeScheduler processing the event loop will batch all rendering updates and dispatch them together at the end of each iteration of the loop.
48+
*/
49+
fun batchRenderingUpdatesInEventLoop() = accessor.batchRenderingUpdatesInEventLoop()
50+
3651
/**
3752
* Overrides the feature flags with the ones provided by the given provider
3853
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<961f1fb0a7ad802a492437f15b1f2dcb>>
7+
* @generated SignedSource<<920bb26d238f935f63a77943df7ef6e2>>
88
*/
99

1010
/**
@@ -21,6 +21,9 @@ package com.facebook.react.internal.featureflags
2121

2222
class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccessor {
2323
private var commonTestFlagCache: Boolean? = null
24+
private var useModernRuntimeSchedulerCache: Boolean? = null
25+
private var enableMicrotasksCache: Boolean? = null
26+
private var batchRenderingUpdatesInEventLoopCache: Boolean? = null
2427

2528
override fun commonTestFlag(): Boolean {
2629
var cached = commonTestFlagCache
@@ -31,6 +34,33 @@ class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccessor {
3134
return cached
3235
}
3336

37+
override fun useModernRuntimeScheduler(): Boolean {
38+
var cached = useModernRuntimeSchedulerCache
39+
if (cached == null) {
40+
cached = ReactNativeFeatureFlagsCxxInterop.useModernRuntimeScheduler()
41+
useModernRuntimeSchedulerCache = cached
42+
}
43+
return cached
44+
}
45+
46+
override fun enableMicrotasks(): Boolean {
47+
var cached = enableMicrotasksCache
48+
if (cached == null) {
49+
cached = ReactNativeFeatureFlagsCxxInterop.enableMicrotasks()
50+
enableMicrotasksCache = cached
51+
}
52+
return cached
53+
}
54+
55+
override fun batchRenderingUpdatesInEventLoop(): Boolean {
56+
var cached = batchRenderingUpdatesInEventLoopCache
57+
if (cached == null) {
58+
cached = ReactNativeFeatureFlagsCxxInterop.batchRenderingUpdatesInEventLoop()
59+
batchRenderingUpdatesInEventLoopCache = cached
60+
}
61+
return cached
62+
}
63+
3464
override fun override(provider: ReactNativeFeatureFlagsProvider) =
3565
ReactNativeFeatureFlagsCxxInterop.override(provider as Any)
3666

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c2e41ac8c3d9471b4cb79f6147cc2bf2>>
7+
* @generated SignedSource<<19d0606854e3e34efe67acf9dc1d26b4>>
88
*/
99

1010
/**
@@ -30,6 +30,12 @@ object ReactNativeFeatureFlagsCxxInterop {
3030

3131
@DoNotStrip @JvmStatic external fun commonTestFlag(): Boolean
3232

33+
@DoNotStrip @JvmStatic external fun useModernRuntimeScheduler(): Boolean
34+
35+
@DoNotStrip @JvmStatic external fun enableMicrotasks(): Boolean
36+
37+
@DoNotStrip @JvmStatic external fun batchRenderingUpdatesInEventLoop(): Boolean
38+
3339
@DoNotStrip @JvmStatic external fun override(provider: Any)
3440

3541
@DoNotStrip @JvmStatic external fun dangerouslyReset()

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<aa1eaeee7b715e5b1d3cbcf9b7a7062e>>
7+
* @generated SignedSource<<932fd2768c81d5a5f49929c89d6659ff>>
88
*/
99

1010
/**
@@ -24,4 +24,10 @@ open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvider {
2424
// but that is more expensive than just duplicating the defaults here.
2525

2626
override fun commonTestFlag(): Boolean = false
27+
28+
override fun useModernRuntimeScheduler(): Boolean = false
29+
30+
override fun enableMicrotasks(): Boolean = false
31+
32+
override fun batchRenderingUpdatesInEventLoop(): Boolean = false
2733
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<8bbd7e8cc2c50cfbf44ba6671d095f23>>
7+
* @generated SignedSource<<6254686d99a8bfd0531ed629655cf673>>
88
*/
99

1010
/**
@@ -25,6 +25,9 @@ class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAccessor {
2525
private val accessedFeatureFlags = mutableSetOf<String>()
2626

2727
private var commonTestFlagCache: Boolean? = null
28+
private var useModernRuntimeSchedulerCache: Boolean? = null
29+
private var enableMicrotasksCache: Boolean? = null
30+
private var batchRenderingUpdatesInEventLoopCache: Boolean? = null
2831

2932
override fun commonTestFlag(): Boolean {
3033
var cached = commonTestFlagCache
@@ -36,6 +39,36 @@ class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAccessor {
3639
return cached
3740
}
3841

42+
override fun useModernRuntimeScheduler(): Boolean {
43+
var cached = useModernRuntimeSchedulerCache
44+
if (cached == null) {
45+
cached = currentProvider.useModernRuntimeScheduler()
46+
accessedFeatureFlags.add("useModernRuntimeScheduler")
47+
useModernRuntimeSchedulerCache = cached
48+
}
49+
return cached
50+
}
51+
52+
override fun enableMicrotasks(): Boolean {
53+
var cached = enableMicrotasksCache
54+
if (cached == null) {
55+
cached = currentProvider.enableMicrotasks()
56+
accessedFeatureFlags.add("enableMicrotasks")
57+
enableMicrotasksCache = cached
58+
}
59+
return cached
60+
}
61+
62+
override fun batchRenderingUpdatesInEventLoop(): Boolean {
63+
var cached = batchRenderingUpdatesInEventLoopCache
64+
if (cached == null) {
65+
cached = currentProvider.batchRenderingUpdatesInEventLoop()
66+
accessedFeatureFlags.add("batchRenderingUpdatesInEventLoop")
67+
batchRenderingUpdatesInEventLoopCache = cached
68+
}
69+
return cached
70+
}
71+
3972
override fun override(provider: ReactNativeFeatureFlagsProvider) {
4073
if (accessedFeatureFlags.isNotEmpty()) {
4174
val accessedFeatureFlagsStr = accessedFeatureFlags.joinToString(separator = ", ") { it }

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<8fae1537ff23fbd7dacd81cc2521cd3c>>
7+
* @generated SignedSource<<c5c87368aae4df966b4b7971aadb79f2>>
88
*/
99

1010
/**
@@ -24,4 +24,10 @@ import com.facebook.proguard.annotations.DoNotStrip
2424
@DoNotStrip
2525
interface ReactNativeFeatureFlagsProvider {
2626
@DoNotStrip fun commonTestFlag(): Boolean
27+
28+
@DoNotStrip fun useModernRuntimeScheduler(): Boolean
29+
30+
@DoNotStrip fun enableMicrotasks(): Boolean
31+
32+
@DoNotStrip fun batchRenderingUpdatesInEventLoop(): Boolean
2733
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactInstance.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,6 @@ public void onHostDestroy() {
170170
// Notify JS if profiling is enabled
171171
boolean isProfiling =
172172
Systrace.isTracing(Systrace.TRACE_TAG_REACT_APPS | Systrace.TRACE_TAG_REACT_JS_VM_CALLS);
173-
// TODO(T166383606): Remove this parameter when we remove the legacy runtime scheduler or we
174-
// have access to ReactNativeConfig before we initialize it.
175-
boolean useModernRuntimeScheduler = ReactFeatureFlags.useModernRuntimeScheduler;
176173
mHybridData =
177174
initHybrid(
178175
jsRuntimeFactory,
@@ -182,8 +179,7 @@ public void onHostDestroy() {
182179
jsTimerExecutor,
183180
reactExceptionManager,
184181
bindingsInstaller,
185-
isProfiling,
186-
useModernRuntimeScheduler);
182+
isProfiling);
187183

188184
// Set up TurboModules
189185
Systrace.beginSection(
@@ -457,8 +453,7 @@ private native HybridData initHybrid(
457453
JSTimerExecutor jsTimerExecutor,
458454
ReactJsExceptionHandler jReactExceptionsManager,
459455
@Nullable BindingsInstaller jBindingsInstaller,
460-
boolean isProfiling,
461-
boolean useModernRuntimeScheduler);
456+
boolean isProfiling);
462457

463458
@DoNotStrip
464459
private static native JSTimerExecutor createJSTimerExecutor();

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ad6d2d1c24334995ba197c7cc0a74dc9>>
7+
* @generated SignedSource<<bd4482119f1c4963aa4ad1e354f9107d>>
88
*/
99

1010
/**
@@ -28,6 +28,21 @@ bool JReactNativeFeatureFlagsCxxInterop::commonTestFlag(
2828
return ReactNativeFeatureFlags::commonTestFlag();
2929
}
3030

31+
bool JReactNativeFeatureFlagsCxxInterop::useModernRuntimeScheduler(
32+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
33+
return ReactNativeFeatureFlags::useModernRuntimeScheduler();
34+
}
35+
36+
bool JReactNativeFeatureFlagsCxxInterop::enableMicrotasks(
37+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
38+
return ReactNativeFeatureFlags::enableMicrotasks();
39+
}
40+
41+
bool JReactNativeFeatureFlagsCxxInterop::batchRenderingUpdatesInEventLoop(
42+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
43+
return ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop();
44+
}
45+
3146
void JReactNativeFeatureFlagsCxxInterop::override(
3247
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/,
3348
jni::alias_ref<jobject> provider) {
@@ -48,6 +63,15 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
4863
makeNativeMethod(
4964
"commonTestFlag",
5065
JReactNativeFeatureFlagsCxxInterop::commonTestFlag),
66+
makeNativeMethod(
67+
"useModernRuntimeScheduler",
68+
JReactNativeFeatureFlagsCxxInterop::useModernRuntimeScheduler),
69+
makeNativeMethod(
70+
"enableMicrotasks",
71+
JReactNativeFeatureFlagsCxxInterop::enableMicrotasks),
72+
makeNativeMethod(
73+
"batchRenderingUpdatesInEventLoop",
74+
JReactNativeFeatureFlagsCxxInterop::batchRenderingUpdatesInEventLoop),
5175
});
5276
}
5377

0 commit comments

Comments
 (0)