Skip to content

Commit

Permalink
Refactor perf (#67)
Browse files Browse the repository at this point in the history
* delete unused import

* refactor perf; move calls to top
  • Loading branch information
EdmondChuiHW authored May 20, 2024
1 parent bb2b506 commit 8f28e69
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
22 changes: 11 additions & 11 deletions front_end/core/host/RNPerfMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ class RNPerfMetrics {
}
}

registerPerfMetricsGlobalPostMessageHandler(): void {
if (globalThis.enableReactNativePerfMetrics !== true ||
globalThis.enableReactNativePerfMetricsGlobalPostMessage !== true) {
return;
}

this.addEventListener(event => {
window.postMessage({event, tag: 'react-native-chrome-devtools-perf-metrics'}, window.location.origin);
});
}

setLaunchId(launchId: string|null): void {
this.#launchId = launchId;
}
Expand Down Expand Up @@ -80,17 +91,6 @@ function getPerfTimestamp(): DOMHighResTimeStamp {
return performance.timeOrigin + performance.now();
}

export function registerPerfMetricsGlobalPostMessageHandler(): void {
if (globalThis.enableReactNativePerfMetrics !== true ||
globalThis.enableReactNativePerfMetricsGlobalPostMessage !== true) {
return;
}

getInstance().addEventListener(event => {
window.postMessage({event, tag: 'react-native-chrome-devtools-perf-metrics'}, window.location.origin);
});
}

type CommonEventFields = Readonly<{
timestamp: DOMHighResTimeStamp,
launchId: string | void | null,
Expand Down
13 changes: 8 additions & 5 deletions front_end/entrypoints/rn_fusebox/rn_fusebox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ import type * as Platform from '../../core/platform/platform.js';
import type * as Sources from '../../panels/sources/sources.js';
import * as RNExperiments from '../../core/rn_experiments/rn_experiments.js';

/*
* To ensure accurate timing measurements,
* please make sure these perf metrics lines are called ahead of everything else
*/
Host.rnPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();
Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId'));
Host.rnPerfMetrics.entryPointLoadingStarted('rn_fusebox');

const UIStrings = {
/**
*@description Title of the 'React Native' tool in the Network Navigator View, which is part of the Sources tool
Expand Down Expand Up @@ -66,11 +74,6 @@ RNExperiments.RNExperimentsImpl.Instance.enableExperimentsByDefault([
Root.Runtime.ExperimentName.REACT_NATIVE_SPECIFIC_UI,
]);

Host.RNPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();

Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId'));
Host.rnPerfMetrics.entryPointLoadingStarted('rn_fusebox');

class FuseboxClientMetadataModel extends SDK.SDKModel.SDKModel<void> {
constructor(target: SDK.Target.Target) {
super(target);
Expand Down
7 changes: 5 additions & 2 deletions front_end/entrypoints/rn_inspector/rn_inspector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ import type * as Sources from '../../panels/sources/sources.js';
import * as RNExperiments from '../../core/rn_experiments/rn_experiments.js';
import * as Host from '../../core/host/host.js';

Host.RNPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();

/*
* To ensure accurate timing measurements,
* please make sure these perf metrics lines are called ahead of everything else
*/
Host.rnPerfMetrics.registerPerfMetricsGlobalPostMessageHandler();
Host.rnPerfMetrics.setLaunchId(Root.Runtime.Runtime.queryParam('launchId'));
Host.rnPerfMetrics.entryPointLoadingStarted('rn_inspector');

Expand Down

0 comments on commit 8f28e69

Please sign in to comment.