Wire the Android pull model in C++ behind the feature flag (#57579)

Summary:
Pull Request resolved: https://github.com/react/react-native/pull/57579

Makes `enableMountingCoordinatorPullModelAndroid` functional. With the flag on, the commit thread only signals transaction availability and the UI thread pulls and applies at mount time (matching iOS/macOS); with the flag off (default), behavior is byte-for-byte identical.
- `schedulerShouldRenderTransactions`: notifies via JNI (`FabricMountingManager::onTransactionAvailable`) instead of pulling and building the batch.
- `schedulerDidFinishTransaction`: no-op under the pull model.
- `FabricUIManagerBinding::pullAndExecuteTransaction` (new JNI method): pulls the surface's transaction on the UI thread and runs `executeMount`.
- `FabricMountingManager::executeMount`: gains a `synchronous` mode that executes the batch directly on the UI thread.
- The accumulation sites remain gated on `enableAccumulatedUpdatesInRawPropsAndroid`; the pull model requires that flag to be co-enabled, since a pull may collapse several commits into one diff and therefore needs complete accumulated rawProps.

## Changelog:
[Android] [Added] - Wire the pull-model mounting path in C++ behind `enableMountingCoordinatorPullModelAndroid`

Reviewed By: christophpurrer

Differential Revision: D112309053

fbshipit-source-id: 6e3ca5b8fbc8db647356ac555890c2e465890100
This commit is contained in:
Dawid Małecki authored and meta-codesync[bot] committed 2026-07-29 08:01:12 -07:00
1 parent 67a813a948
commit 9da1a01153
8 files changed
+122 -22

No files matched your search

@@ -938,7 +938,8 @@ public class FabricUIManager
long layoutEndTime,
long finishTransactionStartTime,
long finishTransactionEndTime,
int affectedLayoutNodesCount) {
int affectedLayoutNodesCount,
boolean synchronous) {
// When Binding.cpp calls scheduleMountItems during a commit phase, it always calls with
// a BatchMountItem. No other sites call into this with a BatchMountItem, and Binding.cpp only
// calls scheduleMountItems with a BatchMountItem.
@@ -952,8 +953,9 @@ public class FabricUIManager
} else {
shouldSchedule = mountItem != null;
}
// In case of sync rendering, this could be called on the UI thread. Otherwise,
// it should ~always be called on the JS thread.
// In the push model, this is ~always called on the JS thread, or on the UI
// thread in case of sync rendering.
// In the pull model, this is always called on the UI thread, at pull time.
for (UIManagerListener listener : mListeners) {
listener.didScheduleMountItems(this);
}
@@ -968,16 +970,22 @@ public class FabricUIManager
if (shouldSchedule) {
Assertions.assertNotNull(mountItem, "MountItem is null");
mMountItemDispatcher.addMountItem(mountItem);
if (UiThreadUtil.isOnUiThread()) {
Runnable runnable =
new GuardedRunnable(mReactApplicationContext) {
@Override
public void runGuarded() {
mMountItemDispatcher.tryDispatchMountItems();
}
};
runnable.run();
if (synchronous) {
// Pull model: we are already on the UI thread, inside the dispatcher's loop executing
// a PullTransactionMountItem. We don't schedule the item, we execute it directly.
mountItem.execute(mMountingManager);
} else {
mMountItemDispatcher.addMountItem(mountItem);
if (UiThreadUtil.isOnUiThread()) {
Runnable runnable =
new GuardedRunnable(mReactApplicationContext) {
@Override
public void runGuarded() {
mMountItemDispatcher.tryDispatchMountItems();
}
};
runnable.run();
}
}
}
@@ -52,6 +52,13 @@ void FabricMountingManager::onSurfaceStop(SurfaceId surfaceId) {
allocatedViewRegistry_.erase(surfaceId);
}
void FabricMountingManager::onTransactionAvailable(SurfaceId surfaceId) {
static auto onTransactionAvailable =
JFabricUIManager::javaClassStatic()->getMethod<void(jint)>(
"onTransactionAvailable");
onTransactionAvailable(javaUIManager_, surfaceId);
}
bool FabricMountingManager::isViewAllocated(SurfaceId surfaceId, Tag tag) {
std::lock_guard lock(allocatedViewsMutex_);
auto it = allocatedViewRegistry_.find(surfaceId);
@@ -568,7 +575,8 @@ inline void writeUpdateOverflowInsetMountItem(
} // namespace
void FabricMountingManager::executeMount(
const MountingTransaction& transaction) {
const MountingTransaction& transaction,
bool synchronous) {
TraceSection section("FabricMountingManager::executeMount");
std::scoped_lock lock(commitMutex_);
@@ -830,7 +838,8 @@ void FabricMountingManager::executeMount(
jlong,
jlong,
jlong,
jint)>("scheduleMountItem");
jint,
jboolean)>("scheduleMountItem");
if (batchMountItemIntsSize == 0) {
auto finishTransactionEndTime = telemetryTimePointNow();
@@ -845,7 +854,8 @@ void FabricMountingManager::executeMount(
telemetryTimePointToMilliseconds(telemetry.getLayoutEndTime()),
telemetryTimePointToMilliseconds(finishTransactionStartTime),
telemetryTimePointToMilliseconds(finishTransactionEndTime),
telemetry.getAffectedLayoutNodesCount());
telemetry.getAffectedLayoutNodesCount(),
static_cast<jboolean>(synchronous));
return;
}
@@ -1012,7 +1022,8 @@ void FabricMountingManager::executeMount(
telemetryTimePointToMilliseconds(telemetry.getLayoutEndTime()),
telemetryTimePointToMilliseconds(finishTransactionStartTime),
telemetryTimePointToMilliseconds(finishTransactionEndTime),
telemetry.getAffectedLayoutNodesCount());
telemetry.getAffectedLayoutNodesCount(),
static_cast<jboolean>(synchronous));
env->DeleteLocalRef(buffer.ints);
}
@@ -54,7 +54,23 @@ class FabricMountingManager final {
*/
bool isViewAllocated(SurfaceId surfaceId, Tag tag);
void executeMount(const MountingTransaction &transaction);
/*
* Converts the transaction's mutations into an IntBufferBatchMountItem and
* hands it to Java.
*
* In the push model (`synchronous` = false), the batch is
* scheduled onto the UI thread asynchronously.
*
* In the pull model (`synchronous` = true) the batch is
* applied immediately on the calling (UI) thread.
*/
void executeMount(const MountingTransaction &transaction, bool synchronous = false);
/*
* Pull model: notify Java that a transaction is available for `surfaceId` so
* the UI thread can pull it via a PullTransactionMountItem.
*/
void onTransactionAvailable(SurfaceId surfaceId);
void dispatchCommand(const ShadowView &shadowView, const std::string &commandName, const folly::dynamic &args);
@@ -120,6 +120,55 @@ void FabricUIManagerBinding::reportMount(SurfaceId surfaceId) {
scheduler->reportMount(surfaceId);
}
void FabricUIManagerBinding::pullAndExecuteTransaction(SurfaceId surfaceId) {
TraceSection section("FabricUIManagerBinding::pullAndExecuteTransaction");
std::shared_ptr<const MountingCoordinator> mountingCoordinator;
{
std::shared_lock lock(surfaceHandlerRegistryMutex_);
auto iterator = surfaceHandlerRegistry_.find(surfaceId);
if (iterator == surfaceHandlerRegistry_.end()) {
return;
}
const auto* surfaceHandler = std::get_if<SurfaceHandler>(&iterator->second);
jni::local_ref<SurfaceHandlerBinding::jhybridobject> javaSurfaceHandler;
if (surfaceHandler == nullptr) {
javaSurfaceHandler =
std::get<jni::weak_ref<SurfaceHandlerBinding::jhybridobject>>(
iterator->second)
.lockLocal();
if (javaSurfaceHandler) {
surfaceHandler = &javaSurfaceHandler->cthis()->getSurfaceHandler();
}
}
if (surfaceHandler != nullptr) {
mountingCoordinator = surfaceHandler->getMountingCoordinator();
}
}
if (mountingCoordinator == nullptr) {
return;
}
auto mountingManager = getMountingManager("pullAndExecuteTransaction");
if (!mountingManager) {
return;
}
// The UI thread pulls the transaction itself (it may accumulate several
// revisions committed since the notification was enqueued, and may be empty
// if a previous pull already consumed them). willPerformAsynchronously =
// false: the transaction is applied synchronously right here, so no
// `didPerformAsyncTransactions` bookkeeping is needed.
auto mountingTransaction =
mountingCoordinator->pullTransaction(/* willPerformAsynchronously = */
false);
if (mountingTransaction.has_value()) {
mountingManager->executeMount(
*mountingTransaction, /* synchronous = */ true);
}
}
#pragma mark - Surface management
// Used by bridgeless
@@ -678,7 +727,15 @@ void FabricUIManagerBinding::schedulerShouldRenderTransactions(
}
}
if (ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid()) {
if (ReactNativeFeatureFlags::enableMountingCoordinatorPullModelAndroid()) {
// Pull model: do NOT pull the transaction or build the batch here (on the
// commit thread). Just notify Java that a transaction is available; the UI
// thread will pull it via a PullTransactionMountItem and call back into
// `pullAndExecuteTransaction`.
mountingManager->onTransactionAvailable(
mountingCoordinator->getSurfaceId());
} else if (ReactNativeFeatureFlags::
enableAccumulatedUpdatesInRawPropsAndroid()) {
auto mountingTransaction = mountingCoordinator->pullTransaction(
/* willPerformAsynchronously = */ true);
if (mountingTransaction.has_value()) {
@@ -867,6 +924,9 @@ void FabricUIManagerBinding::registerNatives() {
"drainPreallocateViewsQueue",
FabricUIManagerBinding::drainPreallocateViewsQueue),
makeNativeMethod("reportMount", FabricUIManagerBinding::reportMount),
makeNativeMethod(
"pullAndExecuteTransaction",
FabricUIManagerBinding::pullAndExecuteTransaction),
makeNativeMethod(
"uninstallFabricUIManager",
FabricUIManagerBinding::uninstallFabricUIManager),
@@ -133,6 +133,8 @@ class FabricUIManagerBinding : public jni::HybridClass<FabricUIManagerBinding>,
void reportMount(SurfaceId surfaceId);
void pullAndExecuteTransaction(SurfaceId surfaceId);
jint findNextFocusableElement(jint parentTag, jint focusedTag, jint direction);
jintArray getRelativeAncestorList(jint rootTag, jint childTag);
@@ -2370,12 +2370,13 @@ class facebook::react::FabricMountingManager {
public void destroyUnmountedShadowNode(const facebook::react::ShadowNodeFamily& family);
public void dispatchCommand(const facebook::react::ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args);
public void drainPreallocateViewsQueue();
public void executeMount(const facebook::react::MountingTransaction& transaction);
public void executeMount(const facebook::react::MountingTransaction& transaction, bool synchronous = false);
public void maybePreallocateShadowNode(const facebook::react::ShadowNode& shadowNode);
public void onAllAnimationsComplete();
public void onAnimationStarted();
public void onSurfaceStart(facebook::react::SurfaceId surfaceId);
public void onSurfaceStop(facebook::react::SurfaceId surfaceId);
public void onTransactionAvailable(facebook::react::SurfaceId surfaceId);
public void preallocateShadowView(const facebook::react::ShadowView& shadowView);
public void scheduleReactRevisionMerge(facebook::react::SurfaceId surfaceId);
public void sendAccessibilityEvent(const facebook::react::ShadowView& shadowView, const std::string& eventType);
@@ -2353,12 +2353,13 @@ class facebook::react::FabricMountingManager {
public void destroyUnmountedShadowNode(const facebook::react::ShadowNodeFamily& family);
public void dispatchCommand(const facebook::react::ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args);
public void drainPreallocateViewsQueue();
public void executeMount(const facebook::react::MountingTransaction& transaction);
public void executeMount(const facebook::react::MountingTransaction& transaction, bool synchronous = false);
public void maybePreallocateShadowNode(const facebook::react::ShadowNode& shadowNode);
public void onAllAnimationsComplete();
public void onAnimationStarted();
public void onSurfaceStart(facebook::react::SurfaceId surfaceId);
public void onSurfaceStop(facebook::react::SurfaceId surfaceId);
public void onTransactionAvailable(facebook::react::SurfaceId surfaceId);
public void preallocateShadowView(const facebook::react::ShadowView& shadowView);
public void scheduleReactRevisionMerge(facebook::react::SurfaceId surfaceId);
public void sendAccessibilityEvent(const facebook::react::ShadowView& shadowView, const std::string& eventType);
@@ -2368,12 +2368,13 @@ class facebook::react::FabricMountingManager {
public void destroyUnmountedShadowNode(const facebook::react::ShadowNodeFamily& family);
public void dispatchCommand(const facebook::react::ShadowView& shadowView, const std::string& commandName, const folly::dynamic& args);
public void drainPreallocateViewsQueue();
public void executeMount(const facebook::react::MountingTransaction& transaction);
public void executeMount(const facebook::react::MountingTransaction& transaction, bool synchronous = false);
public void maybePreallocateShadowNode(const facebook::react::ShadowNode& shadowNode);
public void onAllAnimationsComplete();
public void onAnimationStarted();
public void onSurfaceStart(facebook::react::SurfaceId surfaceId);
public void onSurfaceStop(facebook::react::SurfaceId surfaceId);
public void onTransactionAvailable(facebook::react::SurfaceId surfaceId);
public void preallocateShadowView(const facebook::react::ShadowView& shadowView);
public void scheduleReactRevisionMerge(facebook::react::SurfaceId surfaceId);
public void sendAccessibilityEvent(const facebook::react::ShadowView& shadowView, const std::string& eventType);