react-native-macos/Libraries/Core
Emilis Baliukonis 232517a574 Implement nativePerformanceNow to improve Profiler API results (#27885)
Summary:
When experimenting with React Profiler API (https://reactjs.org/docs/profiler.html), I noticed that durations are integers without a debugger, but they are doubles with higher precision when debugger is attached. After digging into React Profiler code, I found out that it's using `performance.now()` to accumulate execution times of individual units of work. Since this method does not exist in React Native, it falls back to Javascript `Date`, leading to imprecise results.

This PR introduces `global.nativePerformanceNow` function which returns precise native time, and a very basic `performance` polyfill with `now` function.

This will greatly improve React Profiler API results, which is essential for profiling and benchmark tools.

Solves https://github.com/facebook/react-native/issues/27274

## Changelog

[General] [Added] - Implement `nativePerformanceNow` and `performance.now()`
Pull Request resolved: https://github.com/facebook/react-native/pull/27885

Test Plan:
```
const initialTime = global.performance.now();
setTimeout(() => {
  const newTime = global.performance.now();
  console.warn('duration', newTime - initialTime);
}, 1000);
```

### Android + Hermes

![Screenshot_1580198068](https://user-images.githubusercontent.com/13116854/73245757-af0d6c80-41b5-11ea-8130-dde14ebd41a3.png)

### Android + JSC

![Screenshot_1580199089](https://user-images.githubusercontent.com/13116854/73246157-92256900-41b6-11ea-87a6-ac222383200c.png)

### iOS

![Simulator Screen Shot - iPhone 8 - 2020-01-28 at 10 06 49](https://user-images.githubusercontent.com/13116854/73245871-f136ae00-41b5-11ea-9e31-b1eff5717e62.png)

Reviewed By: ejanzer

Differential Revision: D19888289

Pulled By: rickhanlonii

fbshipit-source-id: ab8152382da9aee9b4b3c76f096e45d40f55da6c
2020-03-31 10:23:51 -07:00
..
Devtools Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
SegmentFetcher TM JS: Revert to import from TurboModuleRegistry.js 2019-11-08 11:44:16 -08:00
Timers Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
__mocks__ Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
__tests__ Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
ExceptionsManager.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
InitializeCore.js Implement nativePerformanceNow to improve Profiler API results (#27885) 2020-03-31 10:23:51 -07:00
NativeExceptionsManager.js Exact-by-default codemod for react-native-github 2019-11-21 09:42:57 -08:00
ReactFiberErrorDialog.js Convert easy files to flow strict-local 2019-12-05 16:06:46 -08:00
ReactNativeVersion.js Update copyright headers to yearless format 2018-09-11 15:33:07 -07:00
ReactNativeVersionCheck.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
checkNativeVersion.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
polyfillPromise.js Convert easy files to flow strict-local 2019-12-05 16:06:46 -08:00
setUpAlert.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
setUpBatchedBridge.js Backwards-compatible implementation for registerCallableModule 2019-12-17 18:38:57 -08:00
setUpDeveloperTools.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
setUpErrorHandling.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
setUpGlobals.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
setUpNavigator.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
setUpPerformance.js Implement nativePerformanceNow to improve Profiler API results (#27885) 2020-03-31 10:23:51 -07:00
setUpReactDevTools.js Do not explicitly include ".js" in Library imports (#28311) 2020-03-17 02:11:53 -07:00
setUpReactRefresh.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
setUpRegeneratorRuntime.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
setUpSegmentFetcher.js Exact-by-default codemod for react-native-github 2019-11-21 09:42:57 -08:00
setUpSystrace.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00
setUpTimers.js Back out "Upgrade Prettier from 1.17 to 2.0.2." 2020-03-24 21:47:35 -07:00
setUpXHR.js Tidy up license headers [2/n] 2019-10-16 10:06:34 -07:00