Skip to content

Commit

Permalink
Non-Fabric UIModuleManager should not flush View updates if there are…
Browse files Browse the repository at this point in the history
… no non-Fabric views

Summary:
In Fabric, we currently incur the cost of (frequently!) flushing non-Fabric UI updates, even if there are no non-Fabric views.

For now it is still possible to run both renderers at the same time, so we still largely continue to use the non-Fabric path, but only use UIImplementation if there is actually a RootView being managed outside of Fabric.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D29724538

fbshipit-source-id: 0f1148870c04ca9aaed0edfd6b5c55a3756a2bd7
  • Loading branch information
JoshuaGross authored and facebook-github-bot committed Jul 16, 2021
1 parent 4f38cb3 commit 9a78121
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ public interface CustomEventNamesResolver {
private volatile int mViewManagerConstantsCacheSize;

private int mBatchId = 0;
private int mNumRootViews = 0;

@SuppressWarnings("deprecated")
public UIManagerModule(
Expand Down Expand Up @@ -442,6 +443,7 @@ public <T extends View> int addRootView(
-1);

mUIImplementation.registerRootView(rootView, tag, themedRootContext);
mNumRootViews++;
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
return tag;
}
Expand All @@ -465,6 +467,7 @@ public void stopSurface(final int surfaceId) {
@ReactMethod
public void removeRootView(int rootViewTag) {
mUIImplementation.removeRootView(rootViewTag);
mNumRootViews--;
}

public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight) {
Expand Down Expand Up @@ -805,7 +808,12 @@ public void onBatchComplete() {
listener.willDispatchViewUpdates(this);
}
try {
mUIImplementation.dispatchViewUpdates(batchId);
// If there are no RootViews registered, there will be no View updates to dispatch.
// This is a hack to prevent this from being called when Fabric is used everywhere.
// This should no longer be necessary in Bridgeless Mode.
if (mNumRootViews > 0) {
mUIImplementation.dispatchViewUpdates(batchId);
}
} finally {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}
Expand Down

0 comments on commit 9a78121

Please sign in to comment.