Skip to content

Commit

Permalink
Fabric: Implementation of BackgroundExecutor on iOS (and gating)
Browse files Browse the repository at this point in the history
Summary:
This is an implementation of `BackgroundExecutor` on iOS.
In case if the experiment is successful, we will make it mandatory for all platforms.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: JoshuaGross

Differential Revision: D22743722

fbshipit-source-id: 7756d2947e962720b9970d48c74929ab407c0440
  • Loading branch information
shergin authored and facebook-github-bot committed Jul 25, 2020
1 parent d53fc8a commit 8d613c6
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,33 @@ static inline LayoutContext RCTGetLayoutContext()
.fontSizeMultiplier = RCTFontSizeMultiplier()};
}

static dispatch_queue_t RCTGetBackgroundQueue()
{
static dispatch_queue_t queue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
dispatch_queue_attr_t attr =
dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_USER_INTERACTIVE, 0);
queue = dispatch_queue_create("com.facebook.react.background", attr);
});
return queue;
}

static BackgroundExecutor RCTGetBackgroundExecutor()
{
return [](std::function<void()> &&callback) {
if (RCTIsMainQueue()) {
callback();
return;
}

auto copyableCallback = callback;
dispatch_async(RCTGetBackgroundQueue(), ^{
copyableCallback();
});
};
}

@interface RCTSurfacePresenter () <RCTSchedulerDelegate, RCTMountingManagerDelegate>
@end

Expand Down Expand Up @@ -312,6 +339,10 @@ - (RCTScheduler *)_createScheduler
return std::make_unique<MainRunLoopObserver>(activities, owner);
};

if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_background_executor_ios")) {
toolbox.backgroundExecutor = RCTGetBackgroundExecutor();
}

if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_run_loop_based_event_beat_ios")) {
toolbox.synchronousEventBeatFactory = [runtimeExecutor](EventBeat::SharedOwnerBox const &ownerBox) {
auto runLoopObserver =
Expand Down

0 comments on commit 8d613c6

Please sign in to comment.