From 30fe6b341b1e040a001a0a7e9d1ec69f9ed6f19a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rub=C3=A9n=20Norte?= Date: Fri, 23 Sep 2022 05:51:36 -0700 Subject: [PATCH] Restore flags to disable Fabric background executor Summary: We want to fix the order of execution of layout, layout effects and passive effects in React Native, but the use of the Fabric background executor for layout complicates this (and other things). This brings back a flag to disable this background thread to do layout synchronously in JavaScript, before the execution of layout effects and passive effects. This is expected to regress performance on some screens, so we need to address the antipatterns in those screens before shipping this. Changelog: [internal] Reviewed By: javache Differential Revision: D39727131 fbshipit-source-id: 4323b089234d3304ca3bfe5697668fb44ac64c12 --- React/Fabric/RCTSurfacePresenter.mm | 4 +++- ReactAndroid/src/main/jni/react/fabric/Binding.cpp | 7 +++++-- ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp | 5 +++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/React/Fabric/RCTSurfacePresenter.mm b/React/Fabric/RCTSurfacePresenter.mm index 53d4d0dbc75b6f..ff11b061c34c85 100644 --- a/React/Fabric/RCTSurfacePresenter.mm +++ b/React/Fabric/RCTSurfacePresenter.mm @@ -301,7 +301,9 @@ - (RCTScheduler *)_createScheduler return std::make_unique(activities, owner); }; - toolbox.backgroundExecutor = RCTGetBackgroundExecutor(); + if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_background_executor_ios")) { + toolbox.backgroundExecutor = RCTGetBackgroundExecutor(); + } toolbox.synchronousEventBeatFactory = [runtimeExecutor, runtimeScheduler = runtimeScheduler](EventBeat::SharedOwnerBox const &ownerBox) { diff --git a/ReactAndroid/src/main/jni/react/fabric/Binding.cpp b/ReactAndroid/src/main/jni/react/fabric/Binding.cpp index c2ebabec1f029d..3e8dd0075eaaeb 100644 --- a/ReactAndroid/src/main/jni/react/fabric/Binding.cpp +++ b/ReactAndroid/src/main/jni/react/fabric/Binding.cpp @@ -472,8 +472,11 @@ void Binding::installFabricUIManager( toolbox.synchronousEventBeatFactory = synchronousBeatFactory; toolbox.asynchronousEventBeatFactory = asynchronousBeatFactory; - backgroundExecutor_ = JBackgroundExecutor::create("fabric_bg"); - toolbox.backgroundExecutor = backgroundExecutor_; + if (reactNativeConfig_->getBool( + "react_fabric:enable_background_executor_android")) { + backgroundExecutor_ = JBackgroundExecutor::create("fabric_bg"); + toolbox.backgroundExecutor = backgroundExecutor_; + } animationDriver_ = std::make_shared( runtimeExecutor, contextContainer, this); diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index c8af3e88232167..2e31a722444bfe 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -395,8 +395,9 @@ jsi::Value UIManagerBinding::get( RuntimeSchedulerBinding::getBinding(runtime); auto surfaceId = surfaceIdFromValue(runtime, arguments[0]); - if (runtimeSchedulerBinding && - runtimeSchedulerBinding->getIsSynchronous()) { + if (!uiManager->backgroundExecutor_ || + (runtimeSchedulerBinding && + runtimeSchedulerBinding->getIsSynchronous())) { auto weakShadowNodeList = weakShadowNodeListFromValue(runtime, arguments[1]); auto shadowNodeList =