react-native-macos/React
Ramanpreet Nara 4830085f40 Guard all NativeModulePerfLogger calls with a null check
Summary:
## Motivation
We got this crash T67304907, which shows a `EXC_BAD_ACCESS / KERN_INVALID_ADDRESS` when calling this line:
```
  NativeModulePerfLogger::getInstance().asyncMethodCallBatchPreprocessStart();
```
There are no arguments in that call, so I figured the only error could be when we try to invoke `getInstance()` or `asyncMethodCallBatchPreprocessStart()`.

This diff:
1. Removes the `NativeModulePerfLogger::getInstance()` bit. Now NativeModulePerfLogger is used via regular static C functions. So, there's no way that simply invoking one of the logging functions crashes the application: there's no vtable lookup.
2. Inside each logging function, when perf-logging is disabled, the global perflogger should be `nullptr`. This diff makes it so that in that case, we won't execute any code in the control group of the perf-logging experiment.

## Changes
**How do we enable NativeModule perf-logging?**
- Previously:
   - `NativeModulePerfLogger::setInstance(std::make_shared<FBReactNativeModulePerfLogger>(...))`
   - `TurboModulePerfLogger::setInstance(std::make_shared<FBReactNativeModulePerfLogger>(...))`.
- Now:
   - `BridgeNativeModulePerfLogger::enableLogging(std::make_unique<FBReactNativeModulePerfLogger>(...))`
   - `TurboModulePerfLogger::enableLogging(std::make_unique<FBReactNativeModulePerfLogger>(...))`

**How do we do NativeModule perf-logging now?**
- Previously:
   -  `NativeModulePerfLogger::getInstance().command(...args)`
   -  `TurboModulePerfLogger::getInstance().command(...args)`.
- Now:
   - `BridgeNativeModulePerfLogger::command(...args)`
   - `TurboModulePerfLogger::command(...args)`.

The benefit of this approach is that each method in `BridgeNativeModulePerfLogger` is guarded with an if check. Example:

```
void moduleCreateConstructStart(const char *moduleName, int32_t id) {
  NativeModulePerfLogger *logger = g_perfLogger.get();
  if (logger != nullptr) {
    logger->moduleCreateConstructStart(moduleName, id);
  }
}
```

Therefore, we don't actually execute any code when perf-logging is disabled.

Changelog:
[Internal]

Reviewed By: fkgozali

Differential Revision: D21669888

fbshipit-source-id: 80c73754c430ce787404b563878bad146295e01f
2020-05-20 20:19:30 -07:00
..
AccessibilityResources/en.lproj Add localized accessibility strings to React Core pod (#27995) 2020-02-20 14:31:03 -08:00
Base Guard all NativeModulePerfLogger calls with a null check 2020-05-20 20:19:30 -07:00
CoreModules Revert D21396409: Add possibility to disable buttons in action sheet ios 2020-05-19 16:36:32 -07:00
CxxBridge Guard all NativeModulePerfLogger calls with a null check 2020-05-20 20:19:30 -07:00
CxxModule Guard all NativeModulePerfLogger calls with a null check 2020-05-20 20:19:30 -07:00
CxxUtils Clang format for all React Native files 2020-03-08 23:01:17 -07:00
DevSupport Add "Open Debugger" and "Open React DevTools" to iOS dev menu 2020-04-15 19:34:52 -07:00
Fabric iOS-specific LayoutAnimation integration 2020-05-20 19:45:50 -07:00
Inspector Clang format for all React Native files 2020-03-08 23:01:17 -07:00
Modules Clang format for all React Native files 2020-03-08 23:01:17 -07:00
Profiler Clang format for all React Native files 2020-03-08 23:01:17 -07:00
UIUtils Clang format for all React Native files 2020-03-08 23:01:17 -07:00
Views Fix skewX/skewY/perspective/matrix on iOS (#28863) 2020-05-11 09:01:33 -07:00
React-RCTFabric.podspec Updating the URLs to point at new domain name reactnative.dev 2020-02-24 13:09:11 -08:00
third-party.xcconfig Upgrade Folly to v2020.01.13.00 (#27810) 2020-01-21 12:44:00 -08:00