diff --git a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index 5110af0a4ed..a8a5264042b 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -140,4 +140,7 @@ public class ReactFeatureFlags { * Allow Differentiator.cpp and FabricMountingManager.cpp to generate a RemoveDeleteTree mega-op. */ public static boolean enableRemoveDeleteTreeInstruction = false; + + /** Temporary flag to allow execution of mount items up to 15ms earlier than normal. */ + public static boolean enableEarlyScheduledMountItemExecution = false; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java index a2293980c51..e8ab3bdcc16 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -814,6 +814,26 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { if (UiThreadUtil.isOnUiThread()) { // We only read these flags on the UI thread. mMountItemDispatcher.tryDispatchMountItems(); + } else { + // The Choreographer will dispatch any mount items, + // but it only gets called at the /beginning/ of the + // frame - it has no idea if, or when, there is actually work scheduled. That means if we + // have a big chunk of work + // scheduled but the scheduling happens 1ms after the + // start of a UI frame, we'll miss out on 15ms of time + // to perform the work (assuming a 16ms frame). + // The DispatchUIFrameCallback still has value because of + // the PreMountItems that we need to process at a lower + // priority. + if (ReactFeatureFlags.enableEarlyScheduledMountItemExecution) { + UiThreadUtil.runOnUiThread( + new Runnable() { + @Override + public void run() { + mDispatchUIFrameCallback.doFrameGuarded(System.nanoTime()); + } + }); + } } }