Compile out RuntimeScheduler_Legacy under RCT_REMOVE_LEGACY_ARCH (#57116)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/57116

## Changelog:
[General][Breaking] Compile out RuntimeScheduler_Legacy under RCT_REMOVE_LEGACY_ARCH

Guard the legacy RuntimeScheduler implementation behind the `RCT_REMOVE_LEGACY_ARCH` macro instead of deleting it. `RuntimeScheduler_Legacy.h`/`.cpp` remain in the tree, but their contents — along with the feature-flag-based selection between the legacy and modern schedulers in `RuntimeScheduler.cpp`, `NativeMutationObserver.cpp`, and `Task.h` — are wrapped in `#ifndef RCT_REMOVE_LEGACY_ARCH`. When the macro is defined, the legacy code is compiled out and `RuntimeScheduler` unconditionally instantiates `RuntimeScheduler_Modern`; when it is not defined, behavior is unchanged.

The C++ API snapshots are updated to drop the `RuntimeScheduler_Legacy` symbols from the new-arch surface, and the parameterized scheduler test (`RuntimeSchedulerTest`) only runs the modern configuration when the legacy arch is compiled out.

Reviewed By: rubennorte

Differential Revision: D107777881

fbshipit-source-id: 2b50711ab3af182edc45a87fd232d96a0f879837
This commit is contained in:
Christoph Purrer authored and meta-codesync[bot] committed 2026-06-09 09:29:10 -07:00
1 parent 4adca58f4c
commit d205267a5f
9 files changed
+30 -73

No files matched your search

@@ -143,8 +143,11 @@ void NativeMutationObserver::notifyMutationObserversIfNecessary() {
if (dispatchNotification) {
TraceSection s("NativeMutationObserver::notifyObservers");
#ifndef RCT_REMOVE_LEGACY_ARCH
if (ReactNativeFeatureFlags::enableBridgelessArchitecture()) {
#endif
runtime_->queueMicrotask(notifyMutationObservers_.value());
#ifndef RCT_REMOVE_LEGACY_ARCH
} else {
jsInvoker_->invokeAsync([&](jsi::Runtime& runtime) {
// It's possible that the last observer was disconnected before we could
@@ -154,6 +157,7 @@ void NativeMutationObserver::notifyMutationObserversIfNecessary() {
}
});
}
#endif
}
}
@@ -6,12 +6,16 @@
*/
#include "RuntimeScheduler.h"
#include "RuntimeScheduler_Legacy.h"
#include "RuntimeScheduler_Modern.h"
#ifndef RCT_REMOVE_LEGACY_ARCH
#include "RuntimeScheduler_Legacy.h"
#endif
#include <cxxreact/ErrorUtils.h>
#include <cxxreact/TraceSection.h>
#ifndef RCT_REMOVE_LEGACY_ARCH
#include <react/featureflags/ReactNativeFeatureFlags.h>
#endif
#include <utility>
namespace facebook::react {
@@ -23,13 +27,17 @@ std::unique_ptr<RuntimeSchedulerBase> getRuntimeSchedulerImplementation(
RuntimeExecutor runtimeExecutor,
std::function<HighResTimeStamp()> now,
RuntimeSchedulerTaskErrorHandler onTaskError) {
#ifndef RCT_REMOVE_LEGACY_ARCH
if (ReactNativeFeatureFlags::enableBridgelessArchitecture()) {
#endif
return std::make_unique<RuntimeScheduler_Modern>(
std::move(runtimeExecutor), std::move(now), std::move(onTaskError));
#ifndef RCT_REMOVE_LEGACY_ARCH
} else {
return std::make_unique<RuntimeScheduler_Legacy>(
std::move(runtimeExecutor), std::move(now), std::move(onTaskError));
}
#endif
}
} // namespace
@@ -6,6 +6,9 @@
*/
#include "RuntimeScheduler_Legacy.h"
#ifndef RCT_REMOVE_LEGACY_ARCH
#include "SchedulerPriorityUtils.h"
#include <ReactCommon/RuntimeExecutorSyncUIThreadUtils.h>
@@ -282,3 +285,5 @@ void RuntimeScheduler_Legacy::executeTask(
}
} // namespace facebook::react
#endif // RCT_REMOVE_LEGACY_ARCH
@@ -7,6 +7,8 @@
#pragma once
#ifndef RCT_REMOVE_LEGACY_ARCH
#include <ReactCommon/RuntimeExecutor.h>
#include <react/renderer/consistency/ShadowTreeRevisionConsistencyManager.h>
#include <react/renderer/runtimescheduler/RuntimeScheduler.h>
@@ -172,3 +174,5 @@ class RuntimeScheduler_Legacy final : public RuntimeSchedulerBase {
};
} // namespace facebook::react
#endif // RCT_REMOVE_LEGACY_ARCH
@@ -17,7 +17,9 @@
namespace facebook::react {
#ifndef RCT_REMOVE_LEGACY_ARCH
class RuntimeScheduler_Legacy;
#endif
class RuntimeScheduler_Modern;
class TaskPriorityComparer;
@@ -29,7 +31,9 @@ struct Task final : public jsi::NativeState {
Task(SchedulerPriority priority, RawCallback &&callback, HighResTimeStamp expirationTime);
private:
#ifndef RCT_REMOVE_LEGACY_ARCH
friend RuntimeScheduler_Legacy;
#endif
friend RuntimeScheduler_Modern;
friend TaskPriorityComparer;
@@ -1431,6 +1431,10 @@ TEST_P(RuntimeSchedulerTest, reportsLongTasksWithYielding) {
INSTANTIATE_TEST_SUITE_P(
UseModernRuntimeScheduler,
RuntimeSchedulerTest,
#ifdef RCT_REMOVE_LEGACY_ARCH
testing::Values(true));
#else
testing::Values(false, true));
#endif
} // namespace facebook::react
@@ -4264,30 +4264,6 @@ class facebook::react::RuntimeSchedulerIntersectionObserverDelegate {
public virtual ~RuntimeSchedulerIntersectionObserverDelegate() = default;
}
class facebook::react::RuntimeScheduler_Legacy : public facebook::react::RuntimeSchedulerBase {
public RuntimeScheduler_Legacy(const facebook::react::RuntimeScheduler_Legacy&) = delete;
public RuntimeScheduler_Legacy(facebook::react::RuntimeExecutor runtimeExecutor, std::function<facebook::react::HighResTimeStamp()> now, facebook::react::RuntimeSchedulerTaskErrorHandler onTaskError);
public RuntimeScheduler_Legacy(facebook::react::RuntimeScheduler_Legacy&&) = delete;
public facebook::react::RuntimeScheduler_Legacy& operator=(const facebook::react::RuntimeScheduler_Legacy&) = delete;
public facebook::react::RuntimeScheduler_Legacy& operator=(facebook::react::RuntimeScheduler_Legacy&&) = delete;
public virtual bool getShouldYield() noexcept override;
public virtual facebook::react::HighResTimeStamp now() const noexcept override;
public virtual facebook::react::SchedulerPriority getCurrentPriorityLevel() const noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleIdleTask(facebook::jsi::Function&& callback, facebook::react::HighResDuration timeout = timeoutForSchedulerPriority(facebook::react::SchedulerPriority::IdlePriority)) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleIdleTask(facebook::react::RawCallback&& callback, facebook::react::HighResDuration timeout = timeoutForSchedulerPriority(facebook::react::SchedulerPriority::IdlePriority)) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleTask(facebook::react::SchedulerPriority priority, facebook::jsi::Function&& callback) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleTask(facebook::react::SchedulerPriority priority, facebook::react::RawCallback&& callback) noexcept override;
public virtual void callExpiredTasks(facebook::jsi::Runtime& runtime) override;
public virtual void cancelTask(facebook::react::Task& task) noexcept override;
public virtual void executeNowOnTheSameThread(facebook::react::RawCallback&& callback) override;
public virtual void scheduleRenderingUpdate(facebook::react::SurfaceId surfaceId, facebook::react::RuntimeSchedulerRenderingUpdate&& renderingUpdate) override;
public virtual void scheduleWork(facebook::react::RawCallback&& callback) noexcept override;
public virtual void setEventTimingDelegate(facebook::react::RuntimeSchedulerEventTimingDelegate* eventTimingDelegate) override;
public virtual void setIntersectionObserverDelegate(facebook::react::RuntimeSchedulerIntersectionObserverDelegate* intersectionObserverDelegate) override;
public virtual void setPerformanceEntryReporter(facebook::react::PerformanceEntryReporter* performanceEntryReporter) override;
public virtual void setShadowTreeRevisionConsistencyManager(facebook::react::ShadowTreeRevisionConsistencyManager* shadowTreeRevisionConsistencyManager) override;
}
class facebook::react::RuntimeScheduler_Modern : public facebook::react::RuntimeSchedulerBase {
public RuntimeScheduler_Modern(const facebook::react::RuntimeScheduler_Modern&) = delete;
public RuntimeScheduler_Modern(facebook::react::RuntimeExecutor runtimeExecutor, std::function<facebook::react::HighResTimeStamp()> now, facebook::react::RuntimeSchedulerTaskErrorHandler onTaskError);
@@ -6495,30 +6495,6 @@ class facebook::react::RuntimeSchedulerIntersectionObserverDelegate {
public virtual ~RuntimeSchedulerIntersectionObserverDelegate() = default;
}
class facebook::react::RuntimeScheduler_Legacy : public facebook::react::RuntimeSchedulerBase {
public RuntimeScheduler_Legacy(const facebook::react::RuntimeScheduler_Legacy&) = delete;
public RuntimeScheduler_Legacy(facebook::react::RuntimeExecutor runtimeExecutor, std::function<facebook::react::HighResTimeStamp()> now, facebook::react::RuntimeSchedulerTaskErrorHandler onTaskError);
public RuntimeScheduler_Legacy(facebook::react::RuntimeScheduler_Legacy&&) = delete;
public facebook::react::RuntimeScheduler_Legacy& operator=(const facebook::react::RuntimeScheduler_Legacy&) = delete;
public facebook::react::RuntimeScheduler_Legacy& operator=(facebook::react::RuntimeScheduler_Legacy&&) = delete;
public virtual bool getShouldYield() noexcept override;
public virtual facebook::react::HighResTimeStamp now() const noexcept override;
public virtual facebook::react::SchedulerPriority getCurrentPriorityLevel() const noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleIdleTask(facebook::jsi::Function&& callback, facebook::react::HighResDuration timeout = timeoutForSchedulerPriority(facebook::react::SchedulerPriority::IdlePriority)) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleIdleTask(facebook::react::RawCallback&& callback, facebook::react::HighResDuration timeout = timeoutForSchedulerPriority(facebook::react::SchedulerPriority::IdlePriority)) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleTask(facebook::react::SchedulerPriority priority, facebook::jsi::Function&& callback) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleTask(facebook::react::SchedulerPriority priority, facebook::react::RawCallback&& callback) noexcept override;
public virtual void callExpiredTasks(facebook::jsi::Runtime& runtime) override;
public virtual void cancelTask(facebook::react::Task& task) noexcept override;
public virtual void executeNowOnTheSameThread(facebook::react::RawCallback&& callback) override;
public virtual void scheduleRenderingUpdate(facebook::react::SurfaceId surfaceId, facebook::react::RuntimeSchedulerRenderingUpdate&& renderingUpdate) override;
public virtual void scheduleWork(facebook::react::RawCallback&& callback) noexcept override;
public virtual void setEventTimingDelegate(facebook::react::RuntimeSchedulerEventTimingDelegate* eventTimingDelegate) override;
public virtual void setIntersectionObserverDelegate(facebook::react::RuntimeSchedulerIntersectionObserverDelegate* intersectionObserverDelegate) override;
public virtual void setPerformanceEntryReporter(facebook::react::PerformanceEntryReporter* performanceEntryReporter) override;
public virtual void setShadowTreeRevisionConsistencyManager(facebook::react::ShadowTreeRevisionConsistencyManager* shadowTreeRevisionConsistencyManager) override;
}
class facebook::react::RuntimeScheduler_Modern : public facebook::react::RuntimeSchedulerBase {
public RuntimeScheduler_Modern(const facebook::react::RuntimeScheduler_Modern&) = delete;
public RuntimeScheduler_Modern(facebook::react::RuntimeExecutor runtimeExecutor, std::function<facebook::react::HighResTimeStamp()> now, facebook::react::RuntimeSchedulerTaskErrorHandler onTaskError);
@@ -2871,30 +2871,6 @@ class facebook::react::RuntimeSchedulerIntersectionObserverDelegate {
public virtual ~RuntimeSchedulerIntersectionObserverDelegate() = default;
}
class facebook::react::RuntimeScheduler_Legacy : public facebook::react::RuntimeSchedulerBase {
public RuntimeScheduler_Legacy(const facebook::react::RuntimeScheduler_Legacy&) = delete;
public RuntimeScheduler_Legacy(facebook::react::RuntimeExecutor runtimeExecutor, std::function<facebook::react::HighResTimeStamp()> now, facebook::react::RuntimeSchedulerTaskErrorHandler onTaskError);
public RuntimeScheduler_Legacy(facebook::react::RuntimeScheduler_Legacy&&) = delete;
public facebook::react::RuntimeScheduler_Legacy& operator=(const facebook::react::RuntimeScheduler_Legacy&) = delete;
public facebook::react::RuntimeScheduler_Legacy& operator=(facebook::react::RuntimeScheduler_Legacy&&) = delete;
public virtual bool getShouldYield() noexcept override;
public virtual facebook::react::HighResTimeStamp now() const noexcept override;
public virtual facebook::react::SchedulerPriority getCurrentPriorityLevel() const noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleIdleTask(facebook::jsi::Function&& callback, facebook::react::HighResDuration timeout = timeoutForSchedulerPriority(facebook::react::SchedulerPriority::IdlePriority)) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleIdleTask(facebook::react::RawCallback&& callback, facebook::react::HighResDuration timeout = timeoutForSchedulerPriority(facebook::react::SchedulerPriority::IdlePriority)) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleTask(facebook::react::SchedulerPriority priority, facebook::jsi::Function&& callback) noexcept override;
public virtual std::shared_ptr<facebook::react::Task> scheduleTask(facebook::react::SchedulerPriority priority, facebook::react::RawCallback&& callback) noexcept override;
public virtual void callExpiredTasks(facebook::jsi::Runtime& runtime) override;
public virtual void cancelTask(facebook::react::Task& task) noexcept override;
public virtual void executeNowOnTheSameThread(facebook::react::RawCallback&& callback) override;
public virtual void scheduleRenderingUpdate(facebook::react::SurfaceId surfaceId, facebook::react::RuntimeSchedulerRenderingUpdate&& renderingUpdate) override;
public virtual void scheduleWork(facebook::react::RawCallback&& callback) noexcept override;
public virtual void setEventTimingDelegate(facebook::react::RuntimeSchedulerEventTimingDelegate* eventTimingDelegate) override;
public virtual void setIntersectionObserverDelegate(facebook::react::RuntimeSchedulerIntersectionObserverDelegate* intersectionObserverDelegate) override;
public virtual void setPerformanceEntryReporter(facebook::react::PerformanceEntryReporter* performanceEntryReporter) override;
public virtual void setShadowTreeRevisionConsistencyManager(facebook::react::ShadowTreeRevisionConsistencyManager* shadowTreeRevisionConsistencyManager) override;
}
class facebook::react::RuntimeScheduler_Modern : public facebook::react::RuntimeSchedulerBase {
public RuntimeScheduler_Modern(const facebook::react::RuntimeScheduler_Modern&) = delete;
public RuntimeScheduler_Modern(facebook::react::RuntimeExecutor runtimeExecutor, std::function<facebook::react::HighResTimeStamp()> now, facebook::react::RuntimeSchedulerTaskErrorHandler onTaskError);