Skip to content

Commit

Permalink
Setup a global Performance singleton, according to the standard
Browse files Browse the repository at this point in the history
Summary:
Makes sure that the global (standard) `performance` instance is initialized to still both provide `Performance.now()` as before, but also allows for the newly implemented functionality from the WebPerf API, such as marks/measures.

Changelog: [Internal]

Reviewed By: christophpurrer

Differential Revision: D42017812

fbshipit-source-id: ddbe79e91b45a84871de94018305f2a4536ada4b
  • Loading branch information
rshest authored and facebook-github-bot committed Dec 15, 2022
1 parent 61c6788 commit 14307b8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
15 changes: 2 additions & 13 deletions Libraries/Core/setUpPerformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,8 @@
* @format
*/

'use strict';
import Performance from '../WebPerformance/Performance';

if (!global.performance) {
global.performance = ({}: {now?: () => number});
}

/**
* Returns a double, measured in milliseconds.
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
*/
if (typeof global.performance.now !== 'function') {
global.performance.now = function () {
const performanceNow = global.nativePerformanceNow || Date.now;
return performanceNow();
};
global.performance = new Performance();
}
4 changes: 4 additions & 0 deletions Libraries/WebPerformance/Performance.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ export default class Performance {
NativePerformance.clearMeasures(measureName);
}

/**
* Returns a double, measured in milliseconds.
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
*/
now(): HighResTimeStamp {
return getCurrentTimeStamp();
}
Expand Down

0 comments on commit 14307b8

Please sign in to comment.