Skip to content

Commit

Permalink
Restore flags to disable Fabric background executor
Browse files Browse the repository at this point in the history
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
  • Loading branch information
rubennorte authored and facebook-github-bot committed Sep 23, 2022
1 parent 065db68 commit 30fe6b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ - (RCTScheduler *)_createScheduler
return std::make_unique<MainRunLoopObserver>(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) {
Expand Down
7 changes: 5 additions & 2 deletions ReactAndroid/src/main/jni/react/fabric/Binding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LayoutAnimationDriver>(
runtimeExecutor, contextContainer, this);
Expand Down
5 changes: 3 additions & 2 deletions ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 30fe6b3

Please sign in to comment.