From 9a78121ed33b96c3d27596bb4fbb0ff3024fdeba Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Thu, 15 Jul 2021 17:41:00 -0700 Subject: [PATCH] Non-Fabric UIModuleManager should not flush View updates if there are 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 --- .../com/facebook/react/uimanager/UIManagerModule.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index 1d49251377d..6d745f384d7 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -114,6 +114,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule private volatile int mViewManagerConstantsCacheSize; private int mBatchId = 0; + private int mNumRootViews = 0; @SuppressWarnings("deprecated") public UIManagerModule( @@ -442,6 +443,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule -1); mUIImplementation.registerRootView(rootView, tag, themedRootContext); + mNumRootViews++; Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE); return tag; } @@ -465,6 +467,7 @@ public class UIManagerModule extends ReactContextBaseJavaModule @ReactMethod public void removeRootView(int rootViewTag) { mUIImplementation.removeRootView(rootViewTag); + mNumRootViews--; } public void updateNodeSize(int nodeViewTag, int newWidth, int newHeight) { @@ -805,7 +808,12 @@ public class UIManagerModule extends ReactContextBaseJavaModule 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); }