Skip to content

Commit b893582

Browse files
rshestfacebook-github-bot
authored andcommitted
Use by default new Performance API implementation if available
Summary: ## Changelog: [Internal] - Now that Performance API implementation is getting close to the final stage, it should be safe to replace the `global.performance` instance with the corresponding new implementation. This is done *only* if the actual native implementation is present, however (otherwise the behaviour will be exactly the same as before). Currently this is the case for all VR apps, Catalyst and very soon will be the case for fb4a/ios. Reviewed By: cipolleschi Differential Revision: D44057951 fbshipit-source-id: 7ccff4a4930175def69ef4d8a44335fbbd4a5df4
1 parent 102e40a commit b893582

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

Libraries/Core/setUpPerformance.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,29 @@
88
* @format
99
*/
1010

11-
if (!global.performance) {
12-
global.performance = ({}: {now?: () => number});
13-
}
11+
import NativePerformance from '../WebPerformance/NativePerformance';
12+
import Performance from '../WebPerformance/Performance';
1413

15-
/**
16-
* Returns a double, measured in milliseconds.
17-
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
18-
*/
19-
if (typeof global.performance.now !== 'function') {
20-
// $FlowExpectedError[cannot-write] The global isn't writable anywhere but here, where we define it.
21-
global.performance.now = function () {
22-
const performanceNow = global.nativePerformanceNow || Date.now;
23-
return performanceNow();
24-
};
14+
// In case if the native implementation of the Performance API is available, use it,
15+
// otherwise fall back to the legacy/default one, which only defines 'Performance.now()'
16+
if (NativePerformance) {
17+
// $FlowExpectedError[cannot-write]
18+
global.performance = new Performance();
19+
} else {
20+
if (!global.performance) {
21+
// $FlowExpectedError[cannot-write]
22+
global.performance = ({}: {now?: () => number});
23+
}
24+
25+
/**
26+
* Returns a double, measured in milliseconds.
27+
* https://developer.mozilla.org/en-US/docs/Web/API/Performance/now
28+
*/
29+
if (typeof global.performance.now !== 'function') {
30+
// $FlowExpectedError[cannot-write]
31+
global.performance.now = function () {
32+
const performanceNow = global.nativePerformanceNow || Date.now;
33+
return performanceNow();
34+
};
35+
}
2536
}

Libraries/Core/setUpWebPerformance.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)