Skip to content

Commit

Permalink
Back out "Move feature flags for the event loop to ReactNativeFeature…
Browse files Browse the repository at this point in the history
…Flags"

Summary:
Original commit changeset: e30a6f2e12b4

Original Phabricator Diff: D52819137

bypass-github-export-checks

changelog: [internal] internal

Reviewed By: yungsters

Differential Revision: D53113944

fbshipit-source-id: daac6f2bf1e9cd16354987e17cb27f0bcda25f9d
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jan 26, 2024
1 parent 94a9791 commit 31a8bc9
Show file tree
Hide file tree
Showing 46 changed files with 150 additions and 385 deletions.
1 change: 1 addition & 0 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,7 @@ public class com/facebook/react/config/ReactFeatureFlags {
public static field unstable_useFabricInterop Z
public static field unstable_useTurboModuleInterop Z
public static field unstable_useTurboModuleInteropForAllTurboModules Z
public static field useModernRuntimeScheduler Z
public static field useNativeViewConfigsInBridgelessMode Z
public static field useTurboModules Z
public fun <init> ()V
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public class ReactFeatureFlags {
/** When enabled, rawProps in Props will not include Yoga specific props. */
public static boolean excludeYogaFromRawProps = false;

/**
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with
* priorities from any thread.
*/
public static boolean useModernRuntimeScheduler = false;

/**
* Enables storing js caller stack when creating promise in native module. This is useful in case
* of Promise rejection and tracing the cause.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<52367278b4d0fdf7f436bd8c511d4ffe>>
* @generated SignedSource<<c201b2b577ab4aa4bf6071d6b99b43c9>>
*/

/**
Expand Down Expand Up @@ -33,21 +33,6 @@ object ReactNativeFeatureFlags {
*/
fun commonTestFlag() = accessor.commonTestFlag()

/**
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.
*/
fun useModernRuntimeScheduler() = accessor.useModernRuntimeScheduler()

/**
* Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).
*/
fun enableMicrotasks() = accessor.enableMicrotasks()

/**
* 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.
*/
fun batchRenderingUpdatesInEventLoop() = accessor.batchRenderingUpdatesInEventLoop()

/**
* Overrides the feature flags with the ones provided by the given provider
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<920bb26d238f935f63a77943df7ef6e2>>
* @generated SignedSource<<961f1fb0a7ad802a492437f15b1f2dcb>>
*/

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

class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccessor {
private var commonTestFlagCache: Boolean? = null
private var useModernRuntimeSchedulerCache: Boolean? = null
private var enableMicrotasksCache: Boolean? = null
private var batchRenderingUpdatesInEventLoopCache: Boolean? = null

override fun commonTestFlag(): Boolean {
var cached = commonTestFlagCache
Expand All @@ -34,33 +31,6 @@ class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccessor {
return cached
}

override fun useModernRuntimeScheduler(): Boolean {
var cached = useModernRuntimeSchedulerCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.useModernRuntimeScheduler()
useModernRuntimeSchedulerCache = cached
}
return cached
}

override fun enableMicrotasks(): Boolean {
var cached = enableMicrotasksCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.enableMicrotasks()
enableMicrotasksCache = cached
}
return cached
}

override fun batchRenderingUpdatesInEventLoop(): Boolean {
var cached = batchRenderingUpdatesInEventLoopCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.batchRenderingUpdatesInEventLoop()
batchRenderingUpdatesInEventLoopCache = cached
}
return cached
}

override fun override(provider: ReactNativeFeatureFlagsProvider) =
ReactNativeFeatureFlagsCxxInterop.override(provider as Any)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<07894609de6f9d34f7d25d372fd0e6ef>>
* @generated SignedSource<<c2e41ac8c3d9471b4cb79f6147cc2bf2>>
*/

/**
Expand All @@ -29,9 +29,6 @@ object ReactNativeFeatureFlagsCxxInterop {
}

@DoNotStrip @JvmStatic external fun commonTestFlag(): Boolean
@DoNotStrip @JvmStatic external fun useModernRuntimeScheduler(): Boolean
@DoNotStrip @JvmStatic external fun enableMicrotasks(): Boolean
@DoNotStrip @JvmStatic external fun batchRenderingUpdatesInEventLoop(): Boolean

@DoNotStrip @JvmStatic external fun override(provider: Any)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<8c97f44276e919fc32eea07408441404>>
* @generated SignedSource<<aa1eaeee7b715e5b1d3cbcf9b7a7062e>>
*/

/**
Expand All @@ -24,7 +24,4 @@ open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvider {
// but that is more expensive than just duplicating the defaults here.

override fun commonTestFlag(): Boolean = false
override fun useModernRuntimeScheduler(): Boolean = false
override fun enableMicrotasks(): Boolean = false
override fun batchRenderingUpdatesInEventLoop(): Boolean = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<<6254686d99a8bfd0531ed629655cf673>>
* @generated SignedSource<<8bbd7e8cc2c50cfbf44ba6671d095f23>>
*/

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

private var commonTestFlagCache: Boolean? = null
private var useModernRuntimeSchedulerCache: Boolean? = null
private var enableMicrotasksCache: Boolean? = null
private var batchRenderingUpdatesInEventLoopCache: Boolean? = null

override fun commonTestFlag(): Boolean {
var cached = commonTestFlagCache
Expand All @@ -39,36 +36,6 @@ class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAccessor {
return cached
}

override fun useModernRuntimeScheduler(): Boolean {
var cached = useModernRuntimeSchedulerCache
if (cached == null) {
cached = currentProvider.useModernRuntimeScheduler()
accessedFeatureFlags.add("useModernRuntimeScheduler")
useModernRuntimeSchedulerCache = cached
}
return cached
}

override fun enableMicrotasks(): Boolean {
var cached = enableMicrotasksCache
if (cached == null) {
cached = currentProvider.enableMicrotasks()
accessedFeatureFlags.add("enableMicrotasks")
enableMicrotasksCache = cached
}
return cached
}

override fun batchRenderingUpdatesInEventLoop(): Boolean {
var cached = batchRenderingUpdatesInEventLoopCache
if (cached == null) {
cached = currentProvider.batchRenderingUpdatesInEventLoop()
accessedFeatureFlags.add("batchRenderingUpdatesInEventLoop")
batchRenderingUpdatesInEventLoopCache = cached
}
return cached
}

override fun override(provider: ReactNativeFeatureFlagsProvider) {
if (accessedFeatureFlags.isNotEmpty()) {
val accessedFeatureFlagsStr = accessedFeatureFlags.joinToString(separator = ", ") { it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<42a6943246197e110c58027b285bdde5>>
* @generated SignedSource<<babb2b7b32c88b1767ac53ae97dddf10>>
*/

/**
Expand All @@ -21,7 +21,4 @@ package com.facebook.react.internal.featureflags

interface ReactNativeFeatureFlagsProvider {
fun commonTestFlag(): Boolean
fun useModernRuntimeScheduler(): Boolean
fun enableMicrotasks(): Boolean
fun batchRenderingUpdatesInEventLoop(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,9 @@ public void onHostDestroy() {
// Notify JS if profiling is enabled
boolean isProfiling =
Systrace.isTracing(Systrace.TRACE_TAG_REACT_APPS | Systrace.TRACE_TAG_REACT_JS_VM_CALLS);
// TODO(T166383606): Remove this parameter when we remove the legacy runtime scheduler or we
// have access to ReactNativeConfig before we initialize it.
boolean useModernRuntimeScheduler = ReactFeatureFlags.useModernRuntimeScheduler;
mHybridData =
initHybrid(
jsRuntimeFactory,
Expand All @@ -179,7 +182,8 @@ public void onHostDestroy() {
jsTimerExecutor,
reactExceptionManager,
bindingsInstaller,
isProfiling);
isProfiling,
useModernRuntimeScheduler);

// Set up TurboModules
Systrace.beginSection(
Expand Down Expand Up @@ -453,7 +457,8 @@ private native HybridData initHybrid(
JSTimerExecutor jsTimerExecutor,
ReactJsExceptionHandler jReactExceptionsManager,
@Nullable BindingsInstaller jBindingsInstaller,
boolean isProfiling);
boolean isProfiling,
boolean useModernRuntimeScheduler);

@DoNotStrip
private static native JSTimerExecutor createJSTimerExecutor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<bd4482119f1c4963aa4ad1e354f9107d>>
* @generated SignedSource<<ad6d2d1c24334995ba197c7cc0a74dc9>>
*/

/**
Expand All @@ -28,21 +28,6 @@ bool JReactNativeFeatureFlagsCxxInterop::commonTestFlag(
return ReactNativeFeatureFlags::commonTestFlag();
}

bool JReactNativeFeatureFlagsCxxInterop::useModernRuntimeScheduler(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::useModernRuntimeScheduler();
}

bool JReactNativeFeatureFlagsCxxInterop::enableMicrotasks(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableMicrotasks();
}

bool JReactNativeFeatureFlagsCxxInterop::batchRenderingUpdatesInEventLoop(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop();
}

void JReactNativeFeatureFlagsCxxInterop::override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/,
jni::alias_ref<jobject> provider) {
Expand All @@ -63,15 +48,6 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"commonTestFlag",
JReactNativeFeatureFlagsCxxInterop::commonTestFlag),
makeNativeMethod(
"useModernRuntimeScheduler",
JReactNativeFeatureFlagsCxxInterop::useModernRuntimeScheduler),
makeNativeMethod(
"enableMicrotasks",
JReactNativeFeatureFlagsCxxInterop::enableMicrotasks),
makeNativeMethod(
"batchRenderingUpdatesInEventLoop",
JReactNativeFeatureFlagsCxxInterop::batchRenderingUpdatesInEventLoop),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<b7304c29a002ce5a8a612d7a08d798ff>>
* @generated SignedSource<<c759720f6c5f9b884f3eee8f3c104526>>
*/

/**
Expand Down Expand Up @@ -33,15 +33,6 @@ class JReactNativeFeatureFlagsCxxInterop
static bool commonTestFlag(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool useModernRuntimeScheduler(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool enableMicrotasks(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool batchRenderingUpdatesInEventLoop(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static void override(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>,
jni::alias_ref<jobject> provider);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<c8ca074517ac6941d16847c0f30076e8>>
* @generated SignedSource<<7a019bd967a22f93cd9e2e0ddb5201e3>>
*/

/**
Expand All @@ -29,28 +29,4 @@ bool ReactNativeFeatureFlagsProviderHolder::commonTestFlag() {
return method(javaProvider_);
}

bool ReactNativeFeatureFlagsProviderHolder::useModernRuntimeScheduler() {
static const auto method =
facebook::jni::findClassStatic(
"com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider")
->getMethod<jboolean()>("useModernRuntimeScheduler");
return method(javaProvider_);
}

bool ReactNativeFeatureFlagsProviderHolder::enableMicrotasks() {
static const auto method =
facebook::jni::findClassStatic(
"com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider")
->getMethod<jboolean()>("enableMicrotasks");
return method(javaProvider_);
}

bool ReactNativeFeatureFlagsProviderHolder::batchRenderingUpdatesInEventLoop() {
static const auto method =
facebook::jni::findClassStatic(
"com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider")
->getMethod<jboolean()>("batchRenderingUpdatesInEventLoop");
return method(javaProvider_);
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -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<<3550f7ee28a53a4024a48301ee38ce7e>>
* @generated SignedSource<<9a2d162cbd83f3b5122d0eb86f6f9177>>
*/

/**
Expand Down Expand Up @@ -36,9 +36,6 @@ class ReactNativeFeatureFlagsProviderHolder
: javaProvider_(make_global(javaProvider)){};

bool commonTestFlag() override;
bool useModernRuntimeScheduler() override;
bool enableMicrotasks() override;
bool batchRenderingUpdatesInEventLoop() override;

private:
jni::global_ref<jobject> javaProvider_;
Expand Down
Loading

0 comments on commit 31a8bc9

Please sign in to comment.