From 6860ffa35033f06e38b989b026a574569f8bb5b7 Mon Sep 17 00:00:00 2001 From: Ruslan Shestopalyuk Date: Thu, 10 Aug 2023 14:43:29 -0700 Subject: [PATCH] Move nativePerformanceNow binding call into common core code (#38928) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38928 ## Changelog: [Internal] - This moves the call to bind the `nativePerformanceNow` function to the common place in C++ code (`JSIExecutor::initializeRuntime`), as opposed on relying on calling it from every platform-specific implementation. I believe the reason why it was don this way, to begin with, was historical, since we did use to have a different implementation of this function on every platform. Now we have a common one in C++, anyway, so there is no reason whatsoever to have this binding platform-specific. Reviewed By: rubennorte Differential Revision: D48232883 fbshipit-source-id: 164dc464ab7f89e993d83a4562906e033aabb3b7 --- .../React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm | 1 - .../src/main/jni/react/hermes/reactexecutor/OnLoad.cpp | 1 - .../ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp | 1 - .../ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp | 4 ++++ .../ReactCommon/react/bridgeless/ReactInstance.cpp | 5 +++++ 5 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/react-native/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm b/packages/react-native/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm index 5212cdd47af..8cd4c52f655 100644 --- a/packages/react-native/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm +++ b/packages/react-native/React/CxxBridge/RCTJSIExecutorRuntimeInstaller.mm @@ -19,7 +19,6 @@ JSIExecutor::RuntimeInstaller RCTJSIExecutorRuntimeInstaller(JSIExecutor::Runtim _RCTLogJavaScriptInternal(static_cast(logLevel), [NSString stringWithUTF8String:message.c_str()]); }; bindNativeLogger(runtime, iosLoggingBinder); - bindNativePerformanceNow(runtime); // Wrap over the original runtimeInstaller if (runtimeInstaller) { diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp index 795a2ac7b90..296d196bca0 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/hermes/reactexecutor/OnLoad.cpp @@ -46,7 +46,6 @@ static void installBindings(jsi::Runtime &runtime) { static_cast( &reactAndroidLoggingHook); react::bindNativeLogger(runtime, androidLogger); - react::bindNativePerformanceNow(runtime); } class HermesExecutorHolder diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp index fa9a1d2697e..6a812b05be0 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/jscexecutor/OnLoad.cpp @@ -29,7 +29,6 @@ class JSCExecutorFactory : public JSExecutorFactory { static_cast( &reactAndroidLoggingHook); react::bindNativeLogger(runtime, androidLogger); - react::bindNativePerformanceNow(runtime); }; return std::make_unique( jsc::makeJSCRuntime(), diff --git a/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp b/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp index ec882e3da73..03d189e5fa0 100644 --- a/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp +++ b/packages/react-native/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp @@ -81,6 +81,9 @@ JSIExecutor::JSIExecutor( void JSIExecutor::initializeRuntime() { SystraceSection s("JSIExecutor::initializeRuntime"); + + bindNativePerformanceNow(*runtime_); + runtime_->global().setProperty( *runtime_, "nativeModuleProxy", @@ -136,6 +139,7 @@ void JSIExecutor::initializeRuntime() { if (runtimeInstaller_) { runtimeInstaller_(*runtime_); } + bool hasLogger(ReactMarker::logTaggedMarkerImpl); if (hasLogger) { ReactMarker::logMarker(ReactMarker::CREATE_REACT_CONTEXT_STOP); diff --git a/packages/react-native/ReactCommon/react/bridgeless/ReactInstance.cpp b/packages/react-native/ReactCommon/react/bridgeless/ReactInstance.cpp index df9caa868e6..68c2bf706a6 100644 --- a/packages/react-native/ReactCommon/react/bridgeless/ReactInstance.cpp +++ b/packages/react-native/ReactCommon/react/bridgeless/ReactInstance.cpp @@ -9,10 +9,12 @@ #include #include +#include #include #include #include #include +#include #include #include @@ -339,6 +341,9 @@ void ReactInstance::initializeRuntime( runtimeScheduler_->scheduleWork([this, options, bindingsInstallFunc]( jsi::Runtime &runtime) { SystraceSection s("ReactInstance::initializeRuntime"); + + bindNativePerformanceNow(runtime); + RuntimeSchedulerBinding::createAndInstallIfNeeded( runtime, runtimeScheduler_);