Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-native/React/Fabric/RCTScheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)schedulerShouldRenderTransactions:
(std::shared_ptr<const facebook::react::MountingCoordinator>)mountingCoordinator;

- (void)schedulerShouldMergeReactRevision:(facebook::react::SurfaceId)surfaceId;

- (void)schedulerDidDispatchCommand:(const facebook::react::ShadowView &)shadowView
commandName:(const std::string &)commandName
args:(const folly::dynamic &)args;
Expand Down
6 changes: 6 additions & 0 deletions packages/react-native/React/Fabric/RCTScheduler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ void schedulerShouldRenderTransactions(const std::shared_ptr<const MountingCoord
[scheduler.delegate schedulerShouldRenderTransactions:mountingCoordinator];
}

void schedulerShouldMergeReactRevision(SurfaceId surfaceId) override
{
RCTScheduler *scheduler = (__bridge RCTScheduler *)scheduler_;
[scheduler.delegate schedulerShouldMergeReactRevision:surfaceId];
}

void schedulerDidRequestPreliminaryViewAllocation(const ShadowNode &shadowNode) override
{
// Does nothing.
Expand Down
10 changes: 10 additions & 0 deletions packages/react-native/React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,16 @@ - (void)schedulerShouldRenderTransactions:(std::shared_ptr<const MountingCoordin
[_mountingManager scheduleTransaction:mountingCoordinator];
}

- (void)schedulerShouldMergeReactRevision:(SurfaceId)surfaceId
{
auto scheduler = [self scheduler];
RCTExecuteOnMainQueue(^{
RCTAssertMainQueue();
scheduler.uiManager->getShadowTreeRegistry().visit(
surfaceId, [](const ShadowTree &shadowTree) { shadowTree.mergeReactRevision(); });
});
}

- (void)schedulerDidDispatchCommand:(const ShadowView &)shadowView
commandName:(const std::string &)commandName
args:(const folly::dynamic &)args
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,19 @@ public void runGuarded() {
}
}

@SuppressWarnings("unused")
@AnyThread
@ThreadConfined(ANY)
private void scheduleReactRevisionMerge(int surfaceId) {
UiThreadUtil.runOnUiThread(
() -> {
FabricUIManagerBinding binding = mBinding;
if (binding != null) {
binding.mergeReactRevision(surfaceId);
}
});
}

/**
* This method initiates preloading of an image specified by ImageSource. It can later be consumed
* by an ImageView.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ internal class FabricUIManagerBinding : HybridClassBase() {

external fun reportMount(surfaceId: Int)

external fun mergeReactRevision(surfaceId: Int)

fun register(
runtimeExecutor: RuntimeExecutor,
runtimeScheduler: RuntimeScheduler,
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<<adc6b24ae04487d2b82a2bac35f027a7>>
* @generated SignedSource<<41608741730ad508aab1b24e0183ef85>>
*/

/**
Expand Down Expand Up @@ -168,6 +168,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun enableExclusivePropsUpdateAndroid(): Boolean = accessor.enableExclusivePropsUpdateAndroid()

/**
* Enables Fabric commit branching to fix starvation problems and atomic JS updates.
*/
@JvmStatic
public fun enableFabricCommitBranching(): Boolean = accessor.enableFabricCommitBranching()

/**
* This feature flag enables logs for Fabric.
*/
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<<3ebb3c265193b4f61e5bf43082c5be54>>
* @generated SignedSource<<afe25c0d026ce69bb3d08e3631cee312>>
*/

/**
Expand Down Expand Up @@ -43,6 +43,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var enableEagerMainQueueModulesOnIOSCache: Boolean? = null
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableExclusivePropsUpdateAndroidCache: Boolean? = null
private var enableFabricCommitBranchingCache: Boolean? = null
private var enableFabricLogsCache: Boolean? = null
private var enableFabricRendererCache: Boolean? = null
private var enableFontScaleChangesUpdatingLayoutCache: Boolean? = null
Expand Down Expand Up @@ -318,6 +319,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}

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

override fun enableFabricLogs(): Boolean {
var cached = enableFabricLogsCache
if (cached == null) {
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<<eb11cf643c4e94eddc5d7985a8a7a03a>>
* @generated SignedSource<<1547e15c25a3a1fe1a6223c77e60d874>>
*/

/**
Expand Down Expand Up @@ -74,6 +74,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun enableExclusivePropsUpdateAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun enableFabricCommitBranching(): Boolean

@DoNotStrip @JvmStatic public external fun enableFabricLogs(): Boolean

@DoNotStrip @JvmStatic public external fun enableFabricRenderer(): Boolean
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<<bb85527f5c9affa81a1ea33f2873a957>>
* @generated SignedSource<<9bc1dd6111373452e7246ee3682f7e7c>>
*/

/**
Expand Down Expand Up @@ -69,6 +69,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun enableExclusivePropsUpdateAndroid(): Boolean = false

override fun enableFabricCommitBranching(): Boolean = false

override fun enableFabricLogs(): Boolean = false

override fun enableFabricRenderer(): Boolean = false
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<<f9ee0d1f23024b026d065ffc3d48cfcf>>
* @generated SignedSource<<48bf1cbc2c442a6faa0bf64dea60b046>>
*/

/**
Expand Down Expand Up @@ -47,6 +47,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var enableEagerMainQueueModulesOnIOSCache: Boolean? = null
private var enableEagerRootViewAttachmentCache: Boolean? = null
private var enableExclusivePropsUpdateAndroidCache: Boolean? = null
private var enableFabricCommitBranchingCache: Boolean? = null
private var enableFabricLogsCache: Boolean? = null
private var enableFabricRendererCache: Boolean? = null
private var enableFontScaleChangesUpdatingLayoutCache: Boolean? = null
Expand Down Expand Up @@ -345,6 +346,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}

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

override fun enableFabricLogs(): Boolean {
var cached = enableFabricLogsCache
if (cached == null) {
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<<09cef8cedd515f477a32c2ed77d86fc4>>
* @generated SignedSource<<b2358b8652510cd6aa9381a45049ee30>>
*/

/**
Expand Down Expand Up @@ -69,6 +69,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun enableExclusivePropsUpdateAndroid(): Boolean

@DoNotStrip public fun enableFabricCommitBranching(): Boolean

@DoNotStrip public fun enableFabricLogs(): Boolean

@DoNotStrip public fun enableFabricRenderer(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1206,4 +1206,11 @@ void FabricMountingManager::synchronouslyUpdateViewOnUIThread(
synchronouslyUpdateViewOnUIThreadJNI(javaUIManager_, viewTag, propsMap);
}

void FabricMountingManager::scheduleReactRevisionMerge(SurfaceId surfaceId) {
static const auto scheduleReactRevisionMerge =
JFabricUIManager::javaClassStatic()->getMethod<void(int32_t)>(
"scheduleReactRevisionMerge");
scheduleReactRevisionMerge(javaUIManager_, surfaceId);
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class FabricMountingManager final {

void synchronouslyUpdateViewOnUIThread(Tag viewTag, const folly::dynamic &props);

void scheduleReactRevisionMerge(SurfaceId surfaceId);

private:
bool isOnMainThread();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,23 @@ void FabricUIManagerBinding::schedulerShouldRenderTransactions(
}
}

void FabricUIManagerBinding::schedulerShouldMergeReactRevision(
SurfaceId surfaceId) {
std::shared_lock lock(installMutex_);
auto mountingManager =
getMountingManager("schedulerShouldMergeReactRevision");
if (mountingManager) {
mountingManager->scheduleReactRevisionMerge(surfaceId);
}
}

void FabricUIManagerBinding::mergeReactRevision(SurfaceId surfaceId) {
std::shared_lock lock(installMutex_);
scheduler_->getUIManager()->getShadowTreeRegistry().visit(
surfaceId,
[](const ShadowTree& shadowTree) { shadowTree.mergeReactRevision(); });
}

void FabricUIManagerBinding::schedulerDidRequestPreliminaryViewAllocation(
const ShadowNode& shadowNode) {
using namespace std::literals::string_view_literals;
Expand Down Expand Up @@ -816,6 +833,8 @@ void FabricUIManagerBinding::registerNatives() {
makeNativeMethod(
"getRelativeAncestorList",
FabricUIManagerBinding::getRelativeAncestorList),
makeNativeMethod(
"mergeReactRevision", FabricUIManagerBinding::mergeReactRevision),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,
void schedulerShouldRenderTransactions(
const std::shared_ptr<const MountingCoordinator> &mountingCoordinator) override;

void schedulerShouldMergeReactRevision(SurfaceId surfaceId) override;

void mergeReactRevision(SurfaceId surfaceId);

void schedulerDidRequestPreliminaryViewAllocation(const ShadowNode &shadowNode) override;

void schedulerDidDispatchCommand(
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<<b9af351de972ddff807bd25f98f3ff42>>
* @generated SignedSource<<74926c76bdfbb63f36baca7804123cfb>>
*/

/**
Expand Down Expand Up @@ -177,6 +177,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}

bool enableFabricCommitBranching() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableFabricCommitBranching");
return method(javaProvider_);
}

bool enableFabricLogs() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableFabricLogs");
Expand Down Expand Up @@ -698,6 +704,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableExclusivePropsUpdateAndroid(
return ReactNativeFeatureFlags::enableExclusivePropsUpdateAndroid();
}

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

bool JReactNativeFeatureFlagsCxxInterop::enableFabricLogs(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::enableFabricLogs();
Expand Down Expand Up @@ -1133,6 +1144,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"enableExclusivePropsUpdateAndroid",
JReactNativeFeatureFlagsCxxInterop::enableExclusivePropsUpdateAndroid),
makeNativeMethod(
"enableFabricCommitBranching",
JReactNativeFeatureFlagsCxxInterop::enableFabricCommitBranching),
makeNativeMethod(
"enableFabricLogs",
JReactNativeFeatureFlagsCxxInterop::enableFabricLogs),
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<<c89b15dbb7d1cec571eed1551e1b7162>>
* @generated SignedSource<<d2e7a278fd4b8f8308d1a7c402c4f227>>
*/

/**
Expand Down Expand Up @@ -99,6 +99,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool enableExclusivePropsUpdateAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

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

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

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<<08d50062a88a227aa8800e549b6dfe57>>
* @generated SignedSource<<a1fd11b8f74ba91dfc9ed24c61fb36e9>>
*/

/**
Expand Down Expand Up @@ -118,6 +118,10 @@ bool ReactNativeFeatureFlags::enableExclusivePropsUpdateAndroid() {
return getAccessor().enableExclusivePropsUpdateAndroid();
}

bool ReactNativeFeatureFlags::enableFabricCommitBranching() {
return getAccessor().enableFabricCommitBranching();
}

bool ReactNativeFeatureFlags::enableFabricLogs() {
return getAccessor().enableFabricLogs();
}
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<<4f6913d92515fd817a167ef2a505c777>>
* @generated SignedSource<<5ae45db772734aa6c657de764f5ebcf8>>
*/

/**
Expand Down Expand Up @@ -154,6 +154,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool enableExclusivePropsUpdateAndroid();

/**
* Enables Fabric commit branching to fix starvation problems and atomic JS updates.
*/
RN_EXPORT static bool enableFabricCommitBranching();

/**
* This feature flag enables logs for Fabric.
*/
Expand Down
Loading
Loading