From 933a94d7d2765286d7ff6d4c2e18fd5f07f25af0 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Sat, 21 Oct 2023 04:41:45 -0700 Subject: [PATCH] Document MountItemDispatcher (#41114) Summary: changelog: [internal] MountItemDispatcher integrates with FabricUIManager in a non-obvious ways. This diff documents some of that. Reviewed By: NickGerleman Differential Revision: D50494929 --- .../facebook/react/fabric/FabricUIManager.java | 5 +++++ .../fabric/mounting/MountItemDispatcher.java | 16 +++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index c0d9fa2e0ae1dd..fee085185e604c 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -1294,6 +1294,11 @@ public void doFrameGuarded(long frameTimeNanos) { } try { + // First, execute as many pre mount items as we can within frameTimeNanos time. + // If not all pre mount items were executed, following may happen: + // 1. In case there are view commands or mount items in MountItemDispatcher: execute + // remaining pre mount items. + // 2. In case there are no view commands or mount items, wait until next frame. mMountItemDispatcher.dispatchPreMountItems(frameTimeNanos); mMountItemDispatcher.tryDispatchMountItems(); } catch (Exception ex) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java index edf67153d4294f..14589d444e3685 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.java @@ -161,9 +161,17 @@ public void dispatchMountItems(Queue mountItems) { } } + /* + * Executes view commands, pre mount items and mount items in the respective order: + * 1. View commands. + * 2. Pre mount items. + * 3. Regular mount items. + * + * Does nothing if `viewCommandMountItemsToDispatch` and `mountItemsToDispatch` are empty. + * Nothing should call this directly except for `tryDispatchMountItems`. + */ @UiThread @ThreadConfined(UI) - /** Nothing should call this directly except for `tryDispatchMountItems`. */ private boolean dispatchMountItems() { if (mReDispatchCounter == 0) { mBatchedExecutionTime = 0; @@ -296,6 +304,12 @@ private boolean dispatchMountItems() { return true; } + /* + * Executes pre mount items. Pre mount items are operations that can be executed before the mount items come. For example view preallocation. + * This is a performance optimisation to do as much work ahead of time as possible. + * + * `tryDispatchMountItems` will also execute pre mount items, but only if there are mount items to be executed. + */ @UiThread @ThreadConfined(UI) public void dispatchPreMountItems(long frameTimeNanos) {