From 17e16940768080caa47a33141a0c93ed47d4189a Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 11 Feb 2019 14:45:02 -0800 Subject: [PATCH] Stop preallocation views on the main thread Summary: There is no reason to allocate views ahead of time on the main thread. There is a chance that this view will not be mounted and we are not saving any time because it's a sequential process anyway (because we are doing it on the main thread). Moreover, the switching context can only slowdown JS execution. Reviewed By: JoshuaGross Differential Revision: D14026379 fbshipit-source-id: 2dbe93ab32b611fae942468e7812b78afeaf34fc --- .../main/java/com/facebook/react/fabric/FabricUIManager.java | 4 ++++ 1 file changed, 4 insertions(+) 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 b92269c973b..f78ce598784 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/fabric/FabricUIManager.java @@ -191,6 +191,10 @@ public class FabricUIManager implements UIManager, LifecycleEventListener { @DoNotStrip private void preallocateView(final int rootTag, final String componentName) { + if (UiThreadUtil.isOnUiThread()) { + // There is no reason to allocate views ahead of time on the main thread. + return; + } synchronized (mPreMountItemsLock) { ThemedReactContext context = Assertions.assertNotNull(mReactContextForRootTag.get(rootTag));