From bf58ba96f4312b05e4330b80aa913258910b0471 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 11 Feb 2019 12:14:52 -0800 Subject: [PATCH] Fabric: 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: D14019433 fbshipit-source-id: 83ac05a91e4b70cb382a55d6687752480984404e --- React/Fabric/Mounting/RCTMountingManager.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/React/Fabric/Mounting/RCTMountingManager.mm b/React/Fabric/Mounting/RCTMountingManager.mm index c8a575f62..7a1b4831f 100644 --- a/React/Fabric/Mounting/RCTMountingManager.mm +++ b/React/Fabric/Mounting/RCTMountingManager.mm @@ -178,6 +178,11 @@ using namespace facebook::react; - (void)optimisticallyCreateComponentViewWithComponentHandle:(ComponentHandle)componentHandle { + if (RCTIsMainQueue()) { + // There is no reason to allocate views ahead of time on the main thread. + return; + } + RCTExecuteOnMainQueue(^{ [self->_componentViewRegistry optimisticallyCreateComponentViewWithComponentHandle:componentHandle]; });