Replace BridgelessJSCallInvoker with RuntimeSchedulerCallInvoker everywhere (#45409)

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

Changelog: [internal]

This removes `BridgelessJSCallInvoker` in favor of `RuntimeSchedulerCallInvoker`. This change should be transparent when not invoking JS callbacks using priorities, as both of them would just go directly to the scheduler using `scheduleWork`, but when priorities are specified, they'd now be honored in `RuntimeSchedulerCallInvoker`.

I realized this wasn't being used when I saw that `PerformanceObserver` callbacks were always scheduled with the highest priority, instead of with idle priority as specified in code.

Reviewed By: sammy-SC

Differential Revision: D59679512

fbshipit-source-id: 51d36d56ef1ff0b34e5157ed7b5e08de0a3884d2
This commit is contained in:
Rubén Norte
2024-07-15 14:34:06 +01:00
committed by Blake Friedman
parent 2373a0003a
commit 58a525aa2f
4 changed files with 5 additions and 64 deletions
@@ -20,7 +20,7 @@
#include <jsireact/JSIExecutor.h>
#include <react/jni/JRuntimeExecutor.h>
#include <react/jni/JSLogging.h>
#include <react/runtime/BridgelessJSCallInvoker.h>
#include <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
#include <react/runtime/BridgelessNativeMethodCallInvoker.h>
#include "JavaTimerRegistry.h"
@@ -90,8 +90,8 @@ JReactInstance::JReactInstance(
auto unbufferedRuntimeExecutor = instance_->getUnbufferedRuntimeExecutor();
// Set up the JS and native modules call invokers (for TurboModules)
auto jsInvoker =
std::make_unique<BridgelessJSCallInvoker>(unbufferedRuntimeExecutor);
auto jsInvoker = std::make_unique<RuntimeSchedulerCallInvoker>(
instance_->getRuntimeScheduler());
jsCallInvokerHolder_ = jni::make_global(
CallInvokerHolder::newObjectCxxArgs(std::move(jsInvoker)));
auto nativeMethodCallInvoker =
@@ -1,29 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "BridgelessJSCallInvoker.h"
#include <stdexcept>
namespace facebook::react {
BridgelessJSCallInvoker::BridgelessJSCallInvoker(
RuntimeExecutor runtimeExecutor)
: runtimeExecutor_(std::move(runtimeExecutor)) {}
void BridgelessJSCallInvoker::invokeAsync(CallFunc&& func) noexcept {
runtimeExecutor_(
[func = std::move(func)](jsi::Runtime& runtime) { func(runtime); });
}
void BridgelessJSCallInvoker::invokeSync(CallFunc&& /*func*/) {
// TODO: Implement this method. The TurboModule infra doesn't call invokeSync.
throw std::runtime_error(
"Synchronous native -> JS calls are currently not supported.");
}
} // namespace facebook::react
@@ -1,30 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <ReactCommon/CallInvoker.h>
#include <ReactCommon/RuntimeExecutor.h>
#include <functional>
namespace facebook::react {
/**
* A native-to-JS call invoker that uses the RuntimeExecutor. It guarantees that
* any calls from any thread are queued on the right JS thread.
*/
class BridgelessJSCallInvoker : public CallInvoker {
public:
explicit BridgelessJSCallInvoker(RuntimeExecutor runtimeExecutor);
void invokeAsync(CallFunc&& func) noexcept override;
void invokeSync(CallFunc&& func) override;
private:
RuntimeExecutor runtimeExecutor_;
};
} // namespace facebook::react
@@ -37,7 +37,7 @@
#import <cxxreact/ReactMarker.h>
#import <jsinspector-modern/ReactCdp.h>
#import <jsireact/JSIExecutor.h>
#import <react/runtime/BridgelessJSCallInvoker.h>
#import <react/renderer/runtimescheduler/RuntimeSchedulerCallInvoker.h>
#import <react/utils/ContextContainer.h>
#import <react/utils/ManagedObjectWrapper.h>
@@ -249,7 +249,7 @@ void RCTInstanceSetRuntimeDiagnosticFlags(NSString *flags)
RuntimeExecutor bufferedRuntimeExecutor = _reactInstance->getBufferedRuntimeExecutor();
timerManager->setRuntimeExecutor(bufferedRuntimeExecutor);
auto jsCallInvoker = make_shared<BridgelessJSCallInvoker>(bufferedRuntimeExecutor);
auto jsCallInvoker = make_shared<RuntimeSchedulerCallInvoker>(_reactInstance->getRuntimeScheduler());
RCTBridgeProxy *bridgeProxy =
[[RCTBridgeProxy alloc] initWithViewRegistry:_bridgeModuleDecorator.viewRegistry_DEPRECATED
moduleRegistry:_bridgeModuleDecorator.moduleRegistry