Skip to content

Commit

Permalink
move reference to RuntimeScheduler to pointer (#47605)
Browse files Browse the repository at this point in the history
Summary:

changelog: [internal]

use a pointer to RuntimeScheduler instead of getting a reference to it from context container each time.

Reviewed By: javache, cipolleschi

Differential Revision: D65909100
  • Loading branch information
sammy-SC authored and facebook-github-bot committed Nov 15, 2024
1 parent 9a60038 commit 243a0db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ Scheduler::Scheduler(
weakRuntimeScheduler.has_value() &&
"Unexpected state: RuntimeScheduler was not provided.");

auto runtimeScheduler = weakRuntimeScheduler.value().lock();
runtimeScheduler_ = weakRuntimeScheduler.value().lock().get();

if (ReactNativeFeatureFlags::enableUIConsistency()) {
runtimeScheduler->setShadowTreeRevisionConsistencyManager(
runtimeScheduler_->setShadowTreeRevisionConsistencyManager(
uiManager->getShadowTreeRevisionConsistencyManager());
}

if (ReactNativeFeatureFlags::enableReportEventPaintTime()) {
runtimeScheduler->setEventTimingDelegate(eventPerformanceLogger_.get());
runtimeScheduler_->setEventTimingDelegate(eventPerformanceLogger_.get());
}

auto eventPipe = [uiManager, runtimeScheduler = runtimeScheduler.get()](
auto eventPipe = [uiManager](
jsi::Runtime& runtime,
const EventTarget* eventTarget,
const std::string& type,
Expand All @@ -79,12 +79,10 @@ Scheduler::Scheduler(
runtime);
};

auto eventPipeConclusion =
[runtimeScheduler = runtimeScheduler.get()](jsi::Runtime& runtime) {
if (runtimeScheduler != nullptr) {
runtimeScheduler->callExpiredTasks(runtime);
}
};
auto eventPipeConclusion = [runtimeScheduler =
runtimeScheduler_](jsi::Runtime& runtime) {
runtimeScheduler->callExpiredTasks(runtime);
};

auto statePipe = [uiManager](const StateUpdate& stateUpdate) {
uiManager->updateState(stateUpdate);
Expand Down Expand Up @@ -289,16 +287,10 @@ void Scheduler::uiManagerDidFinishTransaction(
// observe each transaction to be able to mount correctly.
delegate_->schedulerDidFinishTransaction(mountingCoordinator);

auto weakRuntimeScheduler =
contextContainer_->find<std::weak_ptr<RuntimeScheduler>>(
"RuntimeScheduler");
auto runtimeScheduler = weakRuntimeScheduler.has_value()
? weakRuntimeScheduler.value().lock()
: nullptr;
if (runtimeScheduler && !mountSynchronously) {
if (!mountSynchronously) {
auto surfaceId = mountingCoordinator->getSurfaceId();

runtimeScheduler->scheduleRenderingUpdate(
runtimeScheduler_->scheduleRenderingUpdate(
surfaceId,
[delegate = delegate_,
mountingCoordinator = std::move(mountingCoordinator)]() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ class Scheduler final : public UIManagerDelegate {
* Must not be nullptr.
*/
ContextContainer::Shared contextContainer_;

RuntimeScheduler* runtimeScheduler_{nullptr};
};

} // namespace facebook::react

0 comments on commit 243a0db

Please sign in to comment.