mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Move feature flags for the event loop to ReactNativeFeatureFlags (#42434)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42434 Changelog: [internal] The flags for the event loop were set up using different mechanisms due to the limitations of the previous feature flags systems. Now we can centralize on the new system and use them consistently on Android and iOS. Reviewed By: RSNara Differential Revision: D52819137 fbshipit-source-id: e30a6f2e12b4a027a906502b80a70dd48bb657b6
This commit is contained in:
committed by
Facebook GitHub Bot
parent
705c675d51
commit
e04d1b47b6
@@ -1918,7 +1918,6 @@ 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
|
||||
|
||||
-6
@@ -130,12 +130,6 @@ 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.
|
||||
|
||||
+16
-1
@@ -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<<c201b2b577ab4aa4bf6071d6b99b43c9>>
|
||||
* @generated SignedSource<<52367278b4d0fdf7f436bd8c511d4ffe>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -33,6 +33,21 @@ 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`).
|
||||
|
||||
+31
-1
@@ -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<<961f1fb0a7ad802a492437f15b1f2dcb>>
|
||||
* @generated SignedSource<<920bb26d238f935f63a77943df7ef6e2>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -21,6 +21,9 @@ 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
|
||||
@@ -31,6 +34,33 @@ 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)
|
||||
|
||||
|
||||
+4
-1
@@ -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<<c2e41ac8c3d9471b4cb79f6147cc2bf2>>
|
||||
* @generated SignedSource<<07894609de6f9d34f7d25d372fd0e6ef>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -29,6 +29,9 @@ 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)
|
||||
|
||||
|
||||
+4
-1
@@ -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<<aa1eaeee7b715e5b1d3cbcf9b7a7062e>>
|
||||
* @generated SignedSource<<8c97f44276e919fc32eea07408441404>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -24,4 +24,7 @@ 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
|
||||
}
|
||||
|
||||
+34
-1
@@ -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<<8bbd7e8cc2c50cfbf44ba6671d095f23>>
|
||||
* @generated SignedSource<<6254686d99a8bfd0531ed629655cf673>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -25,6 +25,9 @@ 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
|
||||
@@ -36,6 +39,36 @@ 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 }
|
||||
|
||||
+4
-1
@@ -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<<babb2b7b32c88b1767ac53ae97dddf10>>
|
||||
* @generated SignedSource<<42a6943246197e110c58027b285bdde5>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -21,4 +21,7 @@ package com.facebook.react.internal.featureflags
|
||||
|
||||
interface ReactNativeFeatureFlagsProvider {
|
||||
fun commonTestFlag(): Boolean
|
||||
fun useModernRuntimeScheduler(): Boolean
|
||||
fun enableMicrotasks(): Boolean
|
||||
fun batchRenderingUpdatesInEventLoop(): Boolean
|
||||
}
|
||||
|
||||
+2
-7
@@ -170,9 +170,6 @@ final class ReactInstance {
|
||||
// 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,
|
||||
@@ -182,8 +179,7 @@ final class ReactInstance {
|
||||
jsTimerExecutor,
|
||||
reactExceptionManager,
|
||||
bindingsInstaller,
|
||||
isProfiling,
|
||||
useModernRuntimeScheduler);
|
||||
isProfiling);
|
||||
|
||||
// Set up TurboModules
|
||||
Systrace.beginSection(
|
||||
@@ -457,8 +453,7 @@ final class ReactInstance {
|
||||
JSTimerExecutor jsTimerExecutor,
|
||||
ReactJsExceptionHandler jReactExceptionsManager,
|
||||
@Nullable BindingsInstaller jBindingsInstaller,
|
||||
boolean isProfiling,
|
||||
boolean useModernRuntimeScheduler);
|
||||
boolean isProfiling);
|
||||
|
||||
@DoNotStrip
|
||||
private static native JSTimerExecutor createJSTimerExecutor();
|
||||
|
||||
+25
-1
@@ -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<<ad6d2d1c24334995ba197c7cc0a74dc9>>
|
||||
* @generated SignedSource<<bd4482119f1c4963aa4ad1e354f9107d>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -28,6 +28,21 @@ 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) {
|
||||
@@ -48,6 +63,15 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
|
||||
makeNativeMethod(
|
||||
"commonTestFlag",
|
||||
JReactNativeFeatureFlagsCxxInterop::commonTestFlag),
|
||||
makeNativeMethod(
|
||||
"useModernRuntimeScheduler",
|
||||
JReactNativeFeatureFlagsCxxInterop::useModernRuntimeScheduler),
|
||||
makeNativeMethod(
|
||||
"enableMicrotasks",
|
||||
JReactNativeFeatureFlagsCxxInterop::enableMicrotasks),
|
||||
makeNativeMethod(
|
||||
"batchRenderingUpdatesInEventLoop",
|
||||
JReactNativeFeatureFlagsCxxInterop::batchRenderingUpdatesInEventLoop),
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -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<<c759720f6c5f9b884f3eee8f3c104526>>
|
||||
* @generated SignedSource<<b7304c29a002ce5a8a612d7a08d798ff>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -33,6 +33,15 @@ 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);
|
||||
|
||||
+25
-1
@@ -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<<7a019bd967a22f93cd9e2e0ddb5201e3>>
|
||||
* @generated SignedSource<<c8ca074517ac6941d16847c0f30076e8>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -29,4 +29,28 @@ 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
|
||||
|
||||
+4
-1
@@ -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<<9a2d162cbd83f3b5122d0eb86f6f9177>>
|
||||
* @generated SignedSource<<3550f7ee28a53a4024a48301ee38ce7e>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -36,6 +36,9 @@ class ReactNativeFeatureFlagsProviderHolder
|
||||
: javaProvider_(make_global(javaProvider)){};
|
||||
|
||||
bool commonTestFlag() override;
|
||||
bool useModernRuntimeScheduler() override;
|
||||
bool enableMicrotasks() override;
|
||||
bool batchRenderingUpdatesInEventLoop() override;
|
||||
|
||||
private:
|
||||
jni::global_ref<jobject> javaProvider_;
|
||||
|
||||
+4
-8
@@ -36,8 +36,7 @@ JReactInstance::JReactInstance(
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
jni::alias_ref<JBindingsInstaller::javaobject> jBindingsInstaller,
|
||||
bool isProfiling,
|
||||
bool useModernRuntimeScheduler) noexcept {
|
||||
bool isProfiling) noexcept {
|
||||
// TODO(janzer): Lazily create runtime
|
||||
auto sharedJSMessageQueueThread =
|
||||
std::make_shared<JMessageQueueThread>(jsMessageQueueThread);
|
||||
@@ -65,8 +64,7 @@ JReactInstance::JReactInstance(
|
||||
jsRuntimeFactory->cthis()->createJSRuntime(sharedJSMessageQueueThread),
|
||||
sharedJSMessageQueueThread,
|
||||
timerManager,
|
||||
std::move(jsErrorHandlingFunc),
|
||||
useModernRuntimeScheduler);
|
||||
std::move(jsErrorHandlingFunc));
|
||||
|
||||
auto bufferedRuntimeExecutor = instance_->getBufferedRuntimeExecutor();
|
||||
timerManager->setRuntimeExecutor(bufferedRuntimeExecutor);
|
||||
@@ -117,8 +115,7 @@ jni::local_ref<JReactInstance::jhybriddata> JReactInstance::initHybrid(
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
jni::alias_ref<JBindingsInstaller::javaobject> jBindingsInstaller,
|
||||
bool isProfiling,
|
||||
bool useModernRuntimeScheduler) {
|
||||
bool isProfiling) {
|
||||
return makeCxxInstance(
|
||||
jsRuntimeFactory,
|
||||
jsMessageQueueThread,
|
||||
@@ -127,8 +124,7 @@ jni::local_ref<JReactInstance::jhybriddata> JReactInstance::initHybrid(
|
||||
jsTimerExecutor,
|
||||
jReactExceptionManager,
|
||||
jBindingsInstaller,
|
||||
isProfiling,
|
||||
useModernRuntimeScheduler);
|
||||
isProfiling);
|
||||
}
|
||||
|
||||
void JReactInstance::loadJSBundleFromAssets(
|
||||
|
||||
@@ -45,8 +45,7 @@ class JReactInstance : public jni::HybridClass<JReactInstance> {
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
jni::alias_ref<JBindingsInstaller::javaobject> jBindingsInstaller,
|
||||
bool isProfiling,
|
||||
bool useModernRuntimeScheduler);
|
||||
bool isProfiling);
|
||||
|
||||
/*
|
||||
* Instantiates and returns an instance of `JSTimerExecutor`.
|
||||
@@ -91,8 +90,7 @@ class JReactInstance : public jni::HybridClass<JReactInstance> {
|
||||
jni::alias_ref<JJSTimerExecutor::javaobject> jsTimerExecutor,
|
||||
jni::alias_ref<JReactExceptionManager::javaobject> jReactExceptionManager,
|
||||
jni::alias_ref<JBindingsInstaller::javaobject> jBindingsInstaller,
|
||||
bool isProfiling,
|
||||
bool useModernRuntimeScheduler) noexcept;
|
||||
bool isProfiling) noexcept;
|
||||
|
||||
jni::alias_ref<CallInvokerHolder::javaobject> getJSCallInvokerHolder();
|
||||
jni::alias_ref<NativeMethodCallInvokerHolder::javaobject>
|
||||
|
||||
@@ -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<<85960128b845159e7de70d0e85910dd9>>
|
||||
* @generated SignedSource<<eb9bb346a84321197849de2dd8bf7dc3>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -25,6 +25,18 @@ bool ReactNativeFeatureFlags::commonTestFlag() {
|
||||
return getAccessor().commonTestFlag();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlags::useModernRuntimeScheduler() {
|
||||
return getAccessor().useModernRuntimeScheduler();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlags::enableMicrotasks() {
|
||||
return getAccessor().enableMicrotasks();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop() {
|
||||
return getAccessor().batchRenderingUpdatesInEventLoop();
|
||||
}
|
||||
|
||||
void ReactNativeFeatureFlags::override(
|
||||
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
|
||||
getAccessor().override(std::move(provider));
|
||||
|
||||
@@ -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<<a4d59ac4d6a845349ffff6ba463fdf80>>
|
||||
* @generated SignedSource<<be203871f94ca134f75b803b7d79a5ab>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -37,6 +37,21 @@ class ReactNativeFeatureFlags {
|
||||
*/
|
||||
static bool commonTestFlag();
|
||||
|
||||
/**
|
||||
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.
|
||||
*/
|
||||
static bool useModernRuntimeScheduler();
|
||||
|
||||
/**
|
||||
* Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).
|
||||
*/
|
||||
static bool 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.
|
||||
*/
|
||||
static bool batchRenderingUpdatesInEventLoop();
|
||||
|
||||
/**
|
||||
* Overrides the feature flags with the ones provided by the given provider
|
||||
* (generally one that extends `ReactNativeFeatureFlagsDefaults`).
|
||||
|
||||
+52
-1
@@ -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<<7f8b2ae5c0b18aceeaac0ee60e53bdbb>>
|
||||
* @generated SignedSource<<5df50987338c0541436b11cd5433013c>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -45,6 +45,57 @@ bool ReactNativeFeatureFlagsAccessor::commonTestFlag() {
|
||||
return commonTestFlag_.value();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlagsAccessor::useModernRuntimeScheduler() {
|
||||
if (!useModernRuntimeScheduler_.has_value()) {
|
||||
// Mark the flag as accessed.
|
||||
static const char* flagName = "useModernRuntimeScheduler";
|
||||
if (std::find(
|
||||
accessedFeatureFlags_.begin(),
|
||||
accessedFeatureFlags_.end(),
|
||||
flagName) == accessedFeatureFlags_.end()) {
|
||||
accessedFeatureFlags_.push_back(flagName);
|
||||
}
|
||||
|
||||
useModernRuntimeScheduler_.emplace(currentProvider_->useModernRuntimeScheduler());
|
||||
}
|
||||
|
||||
return useModernRuntimeScheduler_.value();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlagsAccessor::enableMicrotasks() {
|
||||
if (!enableMicrotasks_.has_value()) {
|
||||
// Mark the flag as accessed.
|
||||
static const char* flagName = "enableMicrotasks";
|
||||
if (std::find(
|
||||
accessedFeatureFlags_.begin(),
|
||||
accessedFeatureFlags_.end(),
|
||||
flagName) == accessedFeatureFlags_.end()) {
|
||||
accessedFeatureFlags_.push_back(flagName);
|
||||
}
|
||||
|
||||
enableMicrotasks_.emplace(currentProvider_->enableMicrotasks());
|
||||
}
|
||||
|
||||
return enableMicrotasks_.value();
|
||||
}
|
||||
|
||||
bool ReactNativeFeatureFlagsAccessor::batchRenderingUpdatesInEventLoop() {
|
||||
if (!batchRenderingUpdatesInEventLoop_.has_value()) {
|
||||
// Mark the flag as accessed.
|
||||
static const char* flagName = "batchRenderingUpdatesInEventLoop";
|
||||
if (std::find(
|
||||
accessedFeatureFlags_.begin(),
|
||||
accessedFeatureFlags_.end(),
|
||||
flagName) == accessedFeatureFlags_.end()) {
|
||||
accessedFeatureFlags_.push_back(flagName);
|
||||
}
|
||||
|
||||
batchRenderingUpdatesInEventLoop_.emplace(currentProvider_->batchRenderingUpdatesInEventLoop());
|
||||
}
|
||||
|
||||
return batchRenderingUpdatesInEventLoop_.value();
|
||||
}
|
||||
|
||||
void ReactNativeFeatureFlagsAccessor::override(
|
||||
std::unique_ptr<ReactNativeFeatureFlagsProvider> provider) {
|
||||
if (!accessedFeatureFlags_.empty()) {
|
||||
|
||||
+7
-1
@@ -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<<3fa0171b372cf6aae150b2ec159fc41e>>
|
||||
* @generated SignedSource<<11335a9c0d793a3a5a0dfdb01cd43efd>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -31,6 +31,9 @@ class ReactNativeFeatureFlagsAccessor {
|
||||
ReactNativeFeatureFlagsAccessor();
|
||||
|
||||
bool commonTestFlag();
|
||||
bool useModernRuntimeScheduler();
|
||||
bool enableMicrotasks();
|
||||
bool batchRenderingUpdatesInEventLoop();
|
||||
|
||||
void override(std::unique_ptr<ReactNativeFeatureFlagsProvider> provider);
|
||||
|
||||
@@ -39,6 +42,9 @@ class ReactNativeFeatureFlagsAccessor {
|
||||
std::vector<const char*> accessedFeatureFlags_;
|
||||
|
||||
std::optional<bool> commonTestFlag_;
|
||||
std::optional<bool> useModernRuntimeScheduler_;
|
||||
std::optional<bool> enableMicrotasks_;
|
||||
std::optional<bool> batchRenderingUpdatesInEventLoop_;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
+13
-1
@@ -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<<76033e9fb87174da88e0ee922df28701>>
|
||||
* @generated SignedSource<<b354cb54b822e2dfa3e093d39fb4da4e>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -30,6 +30,18 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
|
||||
bool commonTestFlag() override {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool useModernRuntimeScheduler() override {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool enableMicrotasks() override {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool batchRenderingUpdatesInEventLoop() override {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
+4
-1
@@ -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<<20dfc971dddc23a6d0cc55938b0d65b7>>
|
||||
* @generated SignedSource<<6bf1fc0d7b32a36041c2371fe191792b>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -26,6 +26,9 @@ class ReactNativeFeatureFlagsProvider {
|
||||
virtual ~ReactNativeFeatureFlagsProvider() = default;
|
||||
|
||||
virtual bool commonTestFlag() = 0;
|
||||
virtual bool useModernRuntimeScheduler() = 0;
|
||||
virtual bool enableMicrotasks() = 0;
|
||||
virtual bool batchRenderingUpdatesInEventLoop() = 0;
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
+16
-1
@@ -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<<f80c7362c3d377edfcbd5cc0642c2464>>
|
||||
* @generated SignedSource<<01b940f6716765f9359c42180db497c0>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -40,4 +40,19 @@ bool NativeReactNativeFeatureFlags::commonTestFlag(
|
||||
return ReactNativeFeatureFlags::commonTestFlag();
|
||||
}
|
||||
|
||||
bool NativeReactNativeFeatureFlags::useModernRuntimeScheduler(
|
||||
jsi::Runtime& /*runtime*/) {
|
||||
return ReactNativeFeatureFlags::useModernRuntimeScheduler();
|
||||
}
|
||||
|
||||
bool NativeReactNativeFeatureFlags::enableMicrotasks(
|
||||
jsi::Runtime& /*runtime*/) {
|
||||
return ReactNativeFeatureFlags::enableMicrotasks();
|
||||
}
|
||||
|
||||
bool NativeReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop(
|
||||
jsi::Runtime& /*runtime*/) {
|
||||
return ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop();
|
||||
}
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
+7
-1
@@ -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<<18a3543b75c44e00bdf73ca2f12d230c>>
|
||||
* @generated SignedSource<<200fe2cf84a044164c60f6dd3c5569dd>>
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -31,6 +31,12 @@ class NativeReactNativeFeatureFlags
|
||||
NativeReactNativeFeatureFlags(std::shared_ptr<CallInvoker> jsInvoker);
|
||||
|
||||
bool commonTestFlag(jsi::Runtime& runtime);
|
||||
|
||||
bool useModernRuntimeScheduler(jsi::Runtime& runtime);
|
||||
|
||||
bool enableMicrotasks(jsi::Runtime& runtime);
|
||||
|
||||
bool batchRenderingUpdatesInEventLoop(jsi::Runtime& runtime);
|
||||
};
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -26,4 +26,5 @@ target_link_libraries(react_render_runtimescheduler
|
||||
react_render_core
|
||||
react_render_debug
|
||||
react_utils
|
||||
react_featureflags
|
||||
runtimeexecutor)
|
||||
|
||||
+1
@@ -56,6 +56,7 @@ Pod::Spec.new do |s|
|
||||
s.dependency "React-cxxreact"
|
||||
s.dependency "React-rendererdebug"
|
||||
s.dependency "React-utils"
|
||||
s.dependency "React-featureflags"
|
||||
s.dependency "glog"
|
||||
s.dependency "RCT-Folly", folly_version
|
||||
s.dependency "React-jsi"
|
||||
|
||||
+2
-4
@@ -10,6 +10,7 @@
|
||||
#include "RuntimeScheduler_Modern.h"
|
||||
#include "SchedulerPriorityUtils.h"
|
||||
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/renderer/debug/SystraceSection.h>
|
||||
#include <utility>
|
||||
#include "ErrorUtils.h"
|
||||
@@ -19,9 +20,8 @@ namespace facebook::react {
|
||||
namespace {
|
||||
std::unique_ptr<RuntimeSchedulerBase> getRuntimeSchedulerImplementation(
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
bool useModernRuntimeScheduler,
|
||||
std::function<RuntimeSchedulerTimePoint()> now) {
|
||||
if (useModernRuntimeScheduler) {
|
||||
if (ReactNativeFeatureFlags::useModernRuntimeScheduler()) {
|
||||
return std::make_unique<RuntimeScheduler_Modern>(
|
||||
std::move(runtimeExecutor), std::move(now));
|
||||
} else {
|
||||
@@ -33,11 +33,9 @@ std::unique_ptr<RuntimeSchedulerBase> getRuntimeSchedulerImplementation(
|
||||
|
||||
RuntimeScheduler::RuntimeScheduler(
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
bool useModernRuntimeScheduler,
|
||||
std::function<RuntimeSchedulerTimePoint()> now)
|
||||
: runtimeSchedulerImpl_(getRuntimeSchedulerImplementation(
|
||||
std::move(runtimeExecutor),
|
||||
useModernRuntimeScheduler,
|
||||
std::move(now))) {}
|
||||
|
||||
void RuntimeScheduler::scheduleWork(RawCallback&& callback) noexcept {
|
||||
|
||||
@@ -44,7 +44,6 @@ class RuntimeScheduler final : RuntimeSchedulerBase {
|
||||
public:
|
||||
explicit RuntimeScheduler(
|
||||
RuntimeExecutor runtimeExecutor,
|
||||
bool useModernRuntimeScheduler = false,
|
||||
std::function<RuntimeSchedulerTimePoint()> now =
|
||||
RuntimeSchedulerClock::now);
|
||||
|
||||
|
||||
+5
-5
@@ -9,8 +9,8 @@
|
||||
#include "SchedulerPriorityUtils.h"
|
||||
|
||||
#include <cxxreact/ErrorUtils.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/renderer/debug/SystraceSection.h>
|
||||
#include <react/utils/CoreFeatures.h>
|
||||
#include <utility>
|
||||
#include "ErrorUtils.h"
|
||||
|
||||
@@ -173,7 +173,7 @@ void RuntimeScheduler_Modern::executeNowOnTheSameThread(
|
||||
|
||||
void RuntimeScheduler_Modern::callExpiredTasks(jsi::Runtime& runtime) {
|
||||
// If we have first-class support for microtasks, this a no-op.
|
||||
if (CoreFeatures::enableMicrotasks) {
|
||||
if (ReactNativeFeatureFlags::enableMicrotasks()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ void RuntimeScheduler_Modern::scheduleRenderingUpdate(
|
||||
RuntimeSchedulerRenderingUpdate&& renderingUpdate) {
|
||||
SystraceSection s("RuntimeScheduler::scheduleRenderingUpdate");
|
||||
|
||||
if (CoreFeatures::blockPaintForUseLayoutEffect) {
|
||||
if (ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop()) {
|
||||
pendingRenderingUpdates_.push(renderingUpdate);
|
||||
} else {
|
||||
if (renderingUpdate != nullptr) {
|
||||
@@ -296,12 +296,12 @@ void RuntimeScheduler_Modern::executeTask(
|
||||
|
||||
executeMacrotask(runtime, task, didUserCallbackTimeout);
|
||||
|
||||
if (CoreFeatures::enableMicrotasks) {
|
||||
if (ReactNativeFeatureFlags::enableMicrotasks()) {
|
||||
// "Perform a microtask checkpoint" step.
|
||||
executeMicrotasks(runtime);
|
||||
}
|
||||
|
||||
if (CoreFeatures::blockPaintForUseLayoutEffect) {
|
||||
if (ReactNativeFeatureFlags::batchRenderingUpdatesInEventLoop()) {
|
||||
// "Update the rendering" step.
|
||||
updateRendering();
|
||||
}
|
||||
|
||||
+37
-10
@@ -8,8 +8,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <hermes/hermes.h>
|
||||
#include <jsi/jsi.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlagsDefaults.h>
|
||||
#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
|
||||
#include <react/utils/CoreFeatures.h>
|
||||
#include <memory>
|
||||
#include <semaphore>
|
||||
|
||||
@@ -21,19 +22,41 @@ namespace facebook::react {
|
||||
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
static bool forcedBatchRenderingUpdatesInEventLoop = false;
|
||||
|
||||
class RuntimeSchedulerTestFeatureFlags
|
||||
: public ReactNativeFeatureFlagsDefaults {
|
||||
public:
|
||||
RuntimeSchedulerTestFeatureFlags(bool useModernRuntimeScheduler)
|
||||
: useModernRuntimeScheduler_(useModernRuntimeScheduler) {}
|
||||
|
||||
bool useModernRuntimeScheduler() override {
|
||||
return useModernRuntimeScheduler_;
|
||||
}
|
||||
|
||||
bool enableMicrotasks() override {
|
||||
return useModernRuntimeScheduler_;
|
||||
}
|
||||
|
||||
bool batchRenderingUpdatesInEventLoop() override {
|
||||
return forcedBatchRenderingUpdatesInEventLoop;
|
||||
}
|
||||
|
||||
private:
|
||||
bool useModernRuntimeScheduler_;
|
||||
};
|
||||
|
||||
class RuntimeSchedulerTest : public testing::TestWithParam<bool> {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
hostFunctionCallCount_ = 0;
|
||||
|
||||
auto useModernRuntimeScheduler = GetParam();
|
||||
|
||||
CoreFeatures::enableMicrotasks = useModernRuntimeScheduler;
|
||||
ReactNativeFeatureFlags::override(
|
||||
std::make_unique<RuntimeSchedulerTestFeatureFlags>(GetParam()));
|
||||
|
||||
// Configuration that enables microtasks
|
||||
::hermes::vm::RuntimeConfig::Builder runtimeConfigBuilder =
|
||||
::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(
|
||||
useModernRuntimeScheduler);
|
||||
::hermes::vm::RuntimeConfig::Builder().withMicrotaskQueue(GetParam());
|
||||
|
||||
runtime_ =
|
||||
facebook::hermes::makeHermesRuntime(runtimeConfigBuilder.build());
|
||||
@@ -54,8 +77,12 @@ class RuntimeSchedulerTest : public testing::TestWithParam<bool> {
|
||||
return stubClock_->getNow();
|
||||
};
|
||||
|
||||
runtimeScheduler_ = std::make_unique<RuntimeScheduler>(
|
||||
runtimeExecutor, useModernRuntimeScheduler, stubNow);
|
||||
runtimeScheduler_ =
|
||||
std::make_unique<RuntimeScheduler>(runtimeExecutor, stubNow);
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
ReactNativeFeatureFlags::dangerouslyReset();
|
||||
}
|
||||
|
||||
jsi::Function createHostFunctionFromLambda(
|
||||
@@ -125,7 +152,7 @@ TEST_P(RuntimeSchedulerTest, scheduleSingleTask) {
|
||||
}
|
||||
|
||||
TEST_P(RuntimeSchedulerTest, scheduleNonBatchedRenderingUpdate) {
|
||||
CoreFeatures::blockPaintForUseLayoutEffect = false;
|
||||
forcedBatchRenderingUpdatesInEventLoop = false;
|
||||
|
||||
bool didRunRenderingUpdate = false;
|
||||
|
||||
@@ -143,7 +170,7 @@ TEST_P(
|
||||
return;
|
||||
}
|
||||
|
||||
CoreFeatures::blockPaintForUseLayoutEffect = true;
|
||||
forcedBatchRenderingUpdatesInEventLoop = true;
|
||||
|
||||
uint nextOperationPosition = 1;
|
||||
|
||||
|
||||
@@ -142,17 +142,6 @@ Scheduler::Scheduler(
|
||||
"react_fabric:remove_outstanding_surfaces_on_destruction_ios");
|
||||
#endif
|
||||
|
||||
#ifdef ANDROID
|
||||
CoreFeatures::enableMicrotasks =
|
||||
reactNativeConfig_->getBool("react_fabric:enable_microtasks_android");
|
||||
#else
|
||||
CoreFeatures::enableMicrotasks =
|
||||
reactNativeConfig_->getBool("react_fabric:enable_microtasks_ios");
|
||||
#endif
|
||||
|
||||
CoreFeatures::blockPaintForUseLayoutEffect = reactNativeConfig_->getBool(
|
||||
"react_fabric:block_paint_for_use_layout_effect");
|
||||
|
||||
CoreFeatures::cacheLastTextMeasurement =
|
||||
reactNativeConfig_->getBool("react_fabric:enable_text_measure_cache");
|
||||
|
||||
|
||||
@@ -37,4 +37,5 @@ target_link_libraries(
|
||||
jsireact
|
||||
react_utils
|
||||
jsinspector
|
||||
react_featureflags
|
||||
)
|
||||
|
||||
@@ -55,6 +55,7 @@ Pod::Spec.new do |s|
|
||||
s.dependency "React-jserrorhandler"
|
||||
s.dependency "React-runtimescheduler"
|
||||
s.dependency "React-utils"
|
||||
s.dependency "React-featureflags"
|
||||
|
||||
if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1"
|
||||
s.dependency "hermes-engine"
|
||||
|
||||
@@ -50,6 +50,7 @@ Pod::Spec.new do |s|
|
||||
s.dependency "React-utils"
|
||||
s.dependency "React-jsi"
|
||||
s.dependency "React-RuntimeCore"
|
||||
s.dependency "React-featureflags"
|
||||
|
||||
if ENV["USE_HERMES"] == nil || ENV["USE_HERMES"] == "1"
|
||||
s.dependency "hermes-engine"
|
||||
|
||||
@@ -15,8 +15,8 @@
|
||||
#include <jsi/JSIDynamic.h>
|
||||
#include <jsi/instrumentation.h>
|
||||
#include <jsireact/JSIExecutor.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
|
||||
#include <react/utils/CoreFeatures.h>
|
||||
|
||||
#include <cxxreact/ReactMarker.h>
|
||||
#include <iostream>
|
||||
@@ -29,8 +29,7 @@ ReactInstance::ReactInstance(
|
||||
std::unique_ptr<JSRuntime> runtime,
|
||||
std::shared_ptr<MessageQueueThread> jsMessageQueueThread,
|
||||
std::shared_ptr<TimerManager> timerManager,
|
||||
JsErrorHandler::JsErrorHandlingFunc jsErrorHandlingFunc,
|
||||
bool useModernRuntimeScheduler)
|
||||
JsErrorHandler::JsErrorHandlingFunc jsErrorHandlingFunc)
|
||||
: runtime_(std::move(runtime)),
|
||||
jsMessageQueueThread_(jsMessageQueueThread),
|
||||
timerManager_(std::move(timerManager)),
|
||||
@@ -70,7 +69,7 @@ ReactInstance::ReactInstance(
|
||||
|
||||
// If we have first-class support for microtasks,
|
||||
// they would've been called as part of the previous callback.
|
||||
if (!CoreFeatures::enableMicrotasks) {
|
||||
if (!ReactNativeFeatureFlags::enableMicrotasks()) {
|
||||
if (auto strongTimerManager = weakTimerManager.lock()) {
|
||||
strongTimerManager->callReactNativeMicrotasks(jsiRuntime);
|
||||
}
|
||||
@@ -83,8 +82,8 @@ ReactInstance::ReactInstance(
|
||||
}
|
||||
};
|
||||
|
||||
runtimeScheduler_ = std::make_shared<RuntimeScheduler>(
|
||||
std::move(runtimeExecutor), useModernRuntimeScheduler);
|
||||
runtimeScheduler_ =
|
||||
std::make_shared<RuntimeScheduler>(std::move(runtimeExecutor));
|
||||
|
||||
auto pipedRuntimeExecutor =
|
||||
[runtimeScheduler = runtimeScheduler_.get()](
|
||||
|
||||
@@ -33,8 +33,7 @@ class ReactInstance final {
|
||||
std::unique_ptr<JSRuntime> runtime,
|
||||
std::shared_ptr<MessageQueueThread> jsMessageQueueThread,
|
||||
std::shared_ptr<TimerManager> timerManager,
|
||||
JsErrorHandler::JsErrorHandlingFunc JsErrorHandlingFunc,
|
||||
bool useModernRuntimeScheduler = false);
|
||||
JsErrorHandler::JsErrorHandlingFunc JsErrorHandlingFunc);
|
||||
|
||||
RuntimeExecutor getUnbufferedRuntimeExecutor() noexcept;
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ target_link_libraries(bridgelesshermes
|
||||
jsi
|
||||
hermes_executor_common
|
||||
bridgeless
|
||||
react_featureflags
|
||||
)
|
||||
|
||||
if(${CMAKE_BUILD_TYPE} MATCHES Debug)
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include <jsi/jsilib.h>
|
||||
#include <jsinspector-modern/InspectorFlags.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
|
||||
#ifdef HERMES_ENABLE_DEBUGGER
|
||||
#include <hermes/inspector-modern/chrome/Registration.h>
|
||||
@@ -107,16 +108,6 @@ std::unique_ptr<JSRuntime> HermesInstance::createJSRuntime(
|
||||
? static_cast<::hermes::vm::gcheapsize_t>(heapSizeConfig)
|
||||
: 3072;
|
||||
|
||||
#ifdef ANDROID
|
||||
bool enableMicrotasks = reactNativeConfig
|
||||
? reactNativeConfig->getBool("react_fabric:enable_microtasks_android")
|
||||
: false;
|
||||
#else
|
||||
bool enableMicrotasks = reactNativeConfig
|
||||
? reactNativeConfig->getBool("react_fabric:enable_microtasks_ios")
|
||||
: false;
|
||||
#endif
|
||||
|
||||
::hermes::vm::RuntimeConfig::Builder runtimeConfigBuilder =
|
||||
::hermes::vm::RuntimeConfig::Builder()
|
||||
.withGCConfig(::hermes::vm::GCConfig::Builder()
|
||||
@@ -131,7 +122,7 @@ std::unique_ptr<JSRuntime> HermesInstance::createJSRuntime(
|
||||
.build())
|
||||
.withES6Proxy(false)
|
||||
.withEnableSampleProfiling(true)
|
||||
.withMicrotaskQueue(enableMicrotasks)
|
||||
.withMicrotaskQueue(ReactNativeFeatureFlags::enableMicrotasks())
|
||||
.withVMExperimentFlags(vmExperimentFlags);
|
||||
|
||||
if (cm) {
|
||||
|
||||
@@ -35,18 +35,6 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* This is a private protocol used to configure internal behavior of the runtime.
|
||||
* DO NOT USE THIS OUTSIDE OF THE REACT NATIVE CODEBASE.
|
||||
*/
|
||||
@protocol RCTHostDelegateInternal <NSObject>
|
||||
|
||||
// TODO(T166383606): Remove this method when we remove the legacy runtime scheduler or we have access to
|
||||
// ReactNativeConfig before we initialize it.
|
||||
- (BOOL)useModernRuntimeScheduler:(RCTHost *)host;
|
||||
|
||||
@end
|
||||
|
||||
@protocol RCTHostRuntimeDelegate <NSObject>
|
||||
|
||||
- (void)host:(RCTHost *)host didInitializeRuntime:(facebook::jsi::Runtime &)runtime;
|
||||
|
||||
+1
-12
@@ -42,7 +42,7 @@ class RCTHostPageTargetDelegate : public facebook::react::jsinspector_modern::Pa
|
||||
__weak RCTHost *host_;
|
||||
};
|
||||
|
||||
@interface RCTHost () <RCTReloadListener, RCTInstanceDelegate, RCTInstanceDelegateInternal>
|
||||
@interface RCTHost () <RCTReloadListener, RCTInstanceDelegate>
|
||||
@end
|
||||
|
||||
@implementation RCTHost {
|
||||
@@ -299,17 +299,6 @@ class RCTHostPageTargetDelegate : public facebook::react::jsinspector_modern::Pa
|
||||
[self.runtimeDelegate host:self didInitializeRuntime:runtime];
|
||||
}
|
||||
|
||||
#pragma mark - RCTInstanceDelegateInternal
|
||||
|
||||
- (BOOL)useModernRuntimeScheduler:(RCTHost *)host
|
||||
{
|
||||
if ([_hostDelegate respondsToSelector:@selector(useModernRuntimeScheduler:)]) {
|
||||
return [(id)_hostDelegate useModernRuntimeScheduler:self];
|
||||
}
|
||||
|
||||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark - RCTContextContainerHandling
|
||||
|
||||
- (void)didCreateContextContainer:(std::shared_ptr<facebook::react::ContextContainer>)contextContainer
|
||||
|
||||
-12
@@ -46,18 +46,6 @@ RCT_EXTERN void RCTInstanceSetRuntimeDiagnosticFlags(NSString *_Nullable flags);
|
||||
|
||||
@end
|
||||
|
||||
/**
|
||||
* This is a private protocol used to configure internal behavior of the runtime.
|
||||
* DO NOT USE THIS OUTSIDE OF THE REACT NATIVE CODEBASE.
|
||||
*/
|
||||
@protocol RCTInstanceDelegateInternal <NSObject>
|
||||
|
||||
// TODO(T166383606): Remove this method when we remove the legacy runtime scheduler or we have access to
|
||||
// ReactNativeConfig before we initialize it.
|
||||
- (BOOL)useModernRuntimeScheduler:(RCTInstance *)instance;
|
||||
|
||||
@end
|
||||
|
||||
typedef void (^_Null_unspecified RCTInstanceInitialBundleLoadCompletionBlock)();
|
||||
|
||||
/**
|
||||
|
||||
+1
-7
@@ -216,18 +216,12 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
|
||||
__weak __typeof(self) weakSelf = self;
|
||||
auto jsErrorHandlingFunc = [=](MapBuffer errorMap) { [weakSelf _handleJSErrorMap:std::move(errorMap)]; };
|
||||
|
||||
auto useModernRuntimeScheduler = false;
|
||||
if ([_delegate respondsToSelector:@selector(useModernRuntimeScheduler:)]) {
|
||||
useModernRuntimeScheduler = [(id)_delegate useModernRuntimeScheduler:self];
|
||||
}
|
||||
|
||||
// Create the React Instance
|
||||
_reactInstance = std::make_unique<ReactInstance>(
|
||||
_jsRuntimeFactory->createJSRuntime(_jsThreadManager.jsMessageThread),
|
||||
_jsThreadManager.jsMessageThread,
|
||||
timerManager,
|
||||
jsErrorHandlingFunc,
|
||||
useModernRuntimeScheduler);
|
||||
jsErrorHandlingFunc);
|
||||
_valid = true;
|
||||
|
||||
RuntimeExecutor bufferedRuntimeExecutor = _reactInstance->getBufferedRuntimeExecutor();
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
namespace facebook::react {
|
||||
|
||||
bool CoreFeatures::enablePropIteratorSetter = false;
|
||||
bool CoreFeatures::blockPaintForUseLayoutEffect = false;
|
||||
bool CoreFeatures::cacheLastTextMeasurement = false;
|
||||
bool CoreFeatures::enableGranularScrollViewStateUpdatesIOS = false;
|
||||
bool CoreFeatures::enableMountHooks = false;
|
||||
@@ -18,7 +17,6 @@ bool CoreFeatures::enableGranularShadowTreeStateReconciliation = false;
|
||||
bool CoreFeatures::enableDefaultAsyncBatchedPriority = false;
|
||||
bool CoreFeatures::enableClonelessStateProgression = false;
|
||||
bool CoreFeatures::excludeYogaFromRawProps = false;
|
||||
bool CoreFeatures::enableMicrotasks = false;
|
||||
bool CoreFeatures::enableReportEventPaintTime = false;
|
||||
|
||||
} // namespace facebook::react
|
||||
|
||||
@@ -19,11 +19,6 @@ class CoreFeatures {
|
||||
// Specifies whether the iterator-style prop parsing is enabled.
|
||||
static bool enablePropIteratorSetter;
|
||||
|
||||
// When enabled, Fabric will block paint to allow for state updates in
|
||||
// useLayoutEffect hooks to be processed. This changes affects scheduling of
|
||||
// when a transaction is mounted.
|
||||
static bool blockPaintForUseLayoutEffect;
|
||||
|
||||
// Yoga might measure multiple times the same Text with the same constraints
|
||||
// This flag enables a caching mechanism to avoid subsequents measurements
|
||||
// of the same Text with the same constrainst.
|
||||
@@ -50,10 +45,6 @@ class CoreFeatures {
|
||||
// When enabled, rawProps in Props will not include Yoga specific props.
|
||||
static bool excludeYogaFromRawProps;
|
||||
|
||||
// Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler
|
||||
// (execution).
|
||||
static bool enableMicrotasks;
|
||||
|
||||
// Report paint time inside the Event Timing API implementation
|
||||
// (PerformanceObserver).
|
||||
static bool enableReportEventPaintTime;
|
||||
|
||||
@@ -3,6 +3,18 @@
|
||||
"commonTestFlag": {
|
||||
"description": "Common flag for testing. Do NOT modify.",
|
||||
"defaultValue": false
|
||||
},
|
||||
"useModernRuntimeScheduler": {
|
||||
"description": "When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.",
|
||||
"defaultValue": false
|
||||
},
|
||||
"enableMicrotasks": {
|
||||
"description": "Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).",
|
||||
"defaultValue": false
|
||||
},
|
||||
"batchRenderingUpdatesInEventLoop": {
|
||||
"description": "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.",
|
||||
"defaultValue": false
|
||||
}
|
||||
},
|
||||
"jsOnly": {
|
||||
|
||||
+4
-1
@@ -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<<ec82a5158f766de0467ab9a38e4ffb15>>
|
||||
* @generated SignedSource<<564159837241d197ebc3084ff9e72b7c>>
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
@@ -24,6 +24,9 @@ import * as TurboModuleRegistry from '../../../Libraries/TurboModule/TurboModule
|
||||
|
||||
export interface Spec extends TurboModule {
|
||||
+commonTestFlag?: () => boolean;
|
||||
+useModernRuntimeScheduler?: () => boolean;
|
||||
+enableMicrotasks?: () => boolean;
|
||||
+batchRenderingUpdatesInEventLoop?: () => boolean;
|
||||
}
|
||||
|
||||
const NativeReactNativeFeatureFlags: ?Spec = TurboModuleRegistry.get<Spec>(
|
||||
|
||||
@@ -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<<b554016876afbf53c25670806a5ff581>>
|
||||
* @generated SignedSource<<4e4ce58c1ce1a95355bba0dfe099e26e>>
|
||||
* @flow strict-local
|
||||
*/
|
||||
|
||||
@@ -34,6 +34,9 @@ export type ReactNativeFeatureFlagsJsOnlyOverrides = Partial<ReactNativeFeatureF
|
||||
export type ReactNativeFeatureFlags = {
|
||||
...ReactNativeFeatureFlagsJsOnly,
|
||||
commonTestFlag: Getter<boolean>,
|
||||
useModernRuntimeScheduler: Getter<boolean>,
|
||||
enableMicrotasks: Getter<boolean>,
|
||||
batchRenderingUpdatesInEventLoop: Getter<boolean>,
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -45,6 +48,18 @@ export const jsOnlyTestFlag: Getter<boolean> = createJavaScriptFlagGetter('jsOnl
|
||||
* Common flag for testing. Do NOT modify.
|
||||
*/
|
||||
export const commonTestFlag: Getter<boolean> = createNativeFlagGetter('commonTestFlag', false);
|
||||
/**
|
||||
* When enabled, it uses the modern fork of RuntimeScheduler that allows scheduling tasks with priorities from any thread.
|
||||
*/
|
||||
export const useModernRuntimeScheduler: Getter<boolean> = createNativeFlagGetter('useModernRuntimeScheduler', false);
|
||||
/**
|
||||
* Enables the use of microtasks in Hermes (scheduling) and RuntimeScheduler (execution).
|
||||
*/
|
||||
export const enableMicrotasks: Getter<boolean> = createNativeFlagGetter('enableMicrotasks', false);
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
export const batchRenderingUpdatesInEventLoop: Getter<boolean> = createNativeFlagGetter('batchRenderingUpdatesInEventLoop', false);
|
||||
|
||||
/**
|
||||
* Overrides the feature flags with the provided methods.
|
||||
|
||||
Reference in New Issue
Block a user