Add ReactMarker::LogTaggedMarkerBridgeless, to replace LogTaggedMarkerWithInstanceKey

Summary:
# Issue in iOS
Before this diff, [Venice would override](https://www.internalfb.com/code/fbsource/[08e6e7a37f9ac1d33e14fc14ed763c0f8716f73a]/fbobjc/Apps/Internal/Venice/Core/RCTPerformanceLoggerUtils.mm?lines=52%2C57) the static function ReactMarker::LogTaggedMarker [created in CxxBridge](https://www.internalfb.com/code/fbsource/[08e6e7a37f9ac1d33e14fc14ed763c0f8716f73a]/xplat/js/react-native-github/React/CxxBridge/RCTCxxBridge.mm?lines=179%2C183). This means that in mixed mode they would share the Bridgeless instance of RCTPerformanceLogger [owned by Venice-only RCTInstance](https://www.internalfb.com/code/fbsource/[08e6e7a37f9ac1d33e14fc14ed763c0f8716f73a]/fbobjc/Apps/Internal/Venice/Core/RCTInstance.mm?lines=65%2C73).

This is wrong because Bridge is supposed to use the instance of RCTPerformanceLogger [owned by RCTBridge](https://www.internalfb.com/code/fbsource/[73ab70b2d9e28569171b62f60e9f25744461d4d9]/xplat/js/react-native-github/React/Base/RCTBridge.m?lines=353).

# Fix iOS and refactor Android

1) Add LogTaggedMarkerBridgeless to use the bridgeless RCTPerformanceLogger.

2) Use LogTaggedMarkerBridgeless to replace logTaggedMarkerWithInstanceKey.
- Remove logTaggedMarkerWithInstanceKey because it always clear from the code that instanceKey is 0 for Bridge, and 1 for Bridgeless,
- iOS doesn't use instanceKey and keeps separate instances of FBReactBridgeStartupLogger, FBReactWildePerfLogger, and RCTPerformanceLogger instead. This is better than using instanceKey because they are all [deallocated when Bridgeless is invalidated](https://www.internalfb.com/code/fbsource/[ea436e5ea6ae4ebc5e206197c4900022be867135]/fbobjc/Apps/Wilde/FBReactModule2/FBReactModuleAPI/FBReactModuleAPI/Exported/FBReactModule.mm?lines=1160%2C1167%2C1170).
- logTaggedMarkerWithInstanceKey is only called from Venice's ReactInstance.cpp so it's easy to remove.

Reviewed By: sshic

Differential Revision: D32588327

fbshipit-source-id: 3151a44c9796da88fef4459b9b56946861514435
This commit is contained in:
Paige Sun 2021-11-23 12:54:08 -08:00 коммит произвёл Facebook GitHub Bot
Родитель 31b64c2615
Коммит 160807d112
5 изменённых файлов: 30 добавлений и 22 удалений

Просмотреть файл

@ -136,8 +136,7 @@ static void notifyAboutModuleSetup(RCTPerformanceLogger *performanceLogger, cons
static void mapReactMarkerToPerformanceLogger( static void mapReactMarkerToPerformanceLogger(
const ReactMarker::ReactMarkerId markerId, const ReactMarker::ReactMarkerId markerId,
RCTPerformanceLogger *performanceLogger, RCTPerformanceLogger *performanceLogger,
const char *tag, const char *tag)
int instanceKey)
{ {
switch (markerId) { switch (markerId) {
case ReactMarker::RUN_JS_BUNDLE_START: case ReactMarker::RUN_JS_BUNDLE_START:
@ -177,13 +176,8 @@ static void registerPerformanceLoggerHooks(RCTPerformanceLogger *performanceLogg
{ {
__weak RCTPerformanceLogger *weakPerformanceLogger = performanceLogger; __weak RCTPerformanceLogger *weakPerformanceLogger = performanceLogger;
ReactMarker::logTaggedMarker = [weakPerformanceLogger](const ReactMarker::ReactMarkerId markerId, const char *tag) { ReactMarker::logTaggedMarker = [weakPerformanceLogger](const ReactMarker::ReactMarkerId markerId, const char *tag) {
mapReactMarkerToPerformanceLogger(markerId, weakPerformanceLogger, tag, 0); mapReactMarkerToPerformanceLogger(markerId, weakPerformanceLogger, tag);
}; };
ReactMarker::logTaggedMarkerWithInstanceKey =
[weakPerformanceLogger](const ReactMarker::ReactMarkerId markerId, const char *tag, const int instanceKey) {
mapReactMarkerToPerformanceLogger(markerId, weakPerformanceLogger, tag, instanceKey);
};
} }
@interface RCTCxxBridge () @interface RCTCxxBridge ()

Просмотреть файл

@ -18,8 +18,8 @@ void JReactMarker::setLogPerfMarkerIfNeeded() {
static std::once_flag flag{}; static std::once_flag flag{};
std::call_once(flag, []() { std::call_once(flag, []() {
ReactMarker::logTaggedMarker = JReactMarker::logPerfMarker; ReactMarker::logTaggedMarker = JReactMarker::logPerfMarker;
ReactMarker::logTaggedMarkerWithInstanceKey = ReactMarker::logTaggedMarkerBridgeless =
JReactMarker::logPerfMarkerWithInstanceKey; JReactMarker::logPerfMarkerBridgeless;
}); });
} }
@ -51,7 +51,15 @@ void JReactMarker::logMarker(
void JReactMarker::logPerfMarker( void JReactMarker::logPerfMarker(
const ReactMarker::ReactMarkerId markerId, const ReactMarker::ReactMarkerId markerId,
const char *tag) { const char *tag) {
logPerfMarkerWithInstanceKey(markerId, tag, 0); const int bridgeInstanceKey = 0;
logPerfMarkerWithInstanceKey(markerId, tag, bridgeInstanceKey);
}
void JReactMarker::logPerfMarkerBridgeless(
const ReactMarker::ReactMarkerId markerId,
const char *tag) {
const int bridgelessInstanceKey = 1;
logPerfMarkerWithInstanceKey(markerId, tag, bridgelessInstanceKey);
} }
void JReactMarker::logPerfMarkerWithInstanceKey( void JReactMarker::logPerfMarkerWithInstanceKey(

Просмотреть файл

@ -31,6 +31,9 @@ class JReactMarker : public facebook::jni::JavaClass<JReactMarker> {
static void logPerfMarker( static void logPerfMarker(
const ReactMarker::ReactMarkerId markerId, const ReactMarker::ReactMarkerId markerId,
const char *tag); const char *tag);
static void logPerfMarkerBridgeless(
const ReactMarker::ReactMarkerId markerId,
const char *tag);
static void logPerfMarkerWithInstanceKey( static void logPerfMarkerWithInstanceKey(
const ReactMarker::ReactMarkerId markerId, const ReactMarker::ReactMarkerId markerId,
const char *tag, const char *tag,

Просмотреть файл

@ -17,7 +17,7 @@ namespace ReactMarker {
#endif #endif
LogTaggedMarker logTaggedMarker = nullptr; LogTaggedMarker logTaggedMarker = nullptr;
LogTaggedMarkerWithInstanceKey logTaggedMarkerWithInstanceKey = nullptr; LogTaggedMarker logTaggedMarkerBridgeless = nullptr;
#if __clang__ #if __clang__
#pragma clang diagnostic pop #pragma clang diagnostic pop
@ -27,6 +27,10 @@ void logMarker(const ReactMarkerId markerId) {
logTaggedMarker(markerId, nullptr); logTaggedMarker(markerId, nullptr);
} }
void logMarkerBridgeless(const ReactMarkerId markerId) {
logTaggedMarkerBridgeless(markerId, nullptr);
}
} // namespace ReactMarker } // namespace ReactMarker
} // namespace react } // namespace react
} // namespace facebook } // namespace facebook

Просмотреть файл

@ -33,25 +33,24 @@ enum ReactMarkerId {
#ifdef __APPLE__ #ifdef __APPLE__
using LogTaggedMarker = using LogTaggedMarker =
std::function<void(const ReactMarkerId, const char *tag)>; // Bridge only
using LogTaggedMarkerBridgeless =
std::function<void(const ReactMarkerId, const char *tag)>; std::function<void(const ReactMarkerId, const char *tag)>;
using LogTaggedMarkerWithInstanceKey = std::function<
void(const ReactMarkerId, const char *tag, const int instanceKey)>;
#else #else
typedef void (*LogTaggedMarker)(const ReactMarkerId, const char *tag); typedef void (
typedef void (*LogTaggedMarkerWithInstanceKey)( *LogTaggedMarker)(const ReactMarkerId, const char *tag); // Bridge only
const ReactMarkerId, typedef void (*LogTaggedMarkerBridgeless)(const ReactMarkerId, const char *tag);
const char *tag,
const int instanceKey);
#endif #endif
#ifndef RN_EXPORT #ifndef RN_EXPORT
#define RN_EXPORT __attribute__((visibility("default"))) #define RN_EXPORT __attribute__((visibility("default")))
#endif #endif
extern RN_EXPORT LogTaggedMarker logTaggedMarker; extern RN_EXPORT LogTaggedMarker logTaggedMarker; // Bridge only
extern RN_EXPORT LogTaggedMarkerWithInstanceKey logTaggedMarkerWithInstanceKey; extern RN_EXPORT LogTaggedMarker logTaggedMarkerBridgeless;
extern RN_EXPORT void logMarker(const ReactMarkerId markerId); extern RN_EXPORT void logMarker(const ReactMarkerId markerId); // Bridge only
extern RN_EXPORT void logMarkerBridgeless(const ReactMarkerId markerId);
} // namespace ReactMarker } // namespace ReactMarker
} // namespace react } // namespace react