Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add React Native perf metrics behind flag #16

Merged
merged 4 commits into from
Mar 12, 2024

Conversation

EdmondChuiHW
Copy link

Summary

This PR enables performance metrics to be collected in internal builds of CDT Frontend for performance, reliability, and efficiency.

  • Adds new flag for React Native perf metrics
    • Default: off, i.e. no-op for open-source
    • Will only be enabled for internal builds, e.g. via a custom embedderScript.js
  • To support setting these configurations before the entry points, embedderScript.js is now a defer script.
    • As type="module" script is defer by definition, the order of these script tags in HTML will be the order of execution per spec.

With the flag enabled, you can use addListener to handle events:

const unsubscribeFn = RNPerfMetrics.Impl.getInstance().addListener(event => console.log(event));

Planned in next PRs

  • Add event type definitions
  • Add callsites for sendEvent(…) (no-op when flag is false/missing)

Test plan

In both release and default builds:

// in embedderScript.js
globalThis.enableReactNativePerfMetrics = true;
globalThis.enableReactNativePerfMetricsGlobalPostMessage = true;

window.addEventListener('message', event => {
  console.log('got em', event.data.tag);
});
// after rn_inspector.ts
RNPerfMetrics.Impl.getInstance().sendEvent({'tag': 'TestyMcTest'});

Expect console to print TestyMcTest

Upstreaming plan

  • This commit should be sent as a patch to the upstream devtools-frontend repo. I've reviewed the contribution guide.
  • This commit is React Native-specific and cannot be upstreamed.

References

Copy link

@hoxyq hoxyq left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, please see the comment about code paths for Meta's license headers

Comment on lines 1 to 8
// Copyright 2024 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Copyright (c) Meta Platforms, Inc. and affiliates.
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you need to add this new file (and other) to

const META_CODE_PATHS = [
'entrypoints/rn_inspector',
'panels/rn_welcome',
];
in order to get correct headers

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Some eslint rule was looking for addEventListener and expects a second param. That crashed so the license linter didn't run either

@EdmondChuiHW EdmondChuiHW merged commit 72a0dbf into facebookexperimental:main Mar 12, 2024
2 checks passed
@EdmondChuiHW EdmondChuiHW deleted the rn-perf-metrics branch March 12, 2024 15:22
@@ -69,6 +69,7 @@ const EXCLUDED_FILES = [
const META_CODE_PATHS = [
'entrypoints/rn_inspector',
'panels/rn_welcome',
'core/host/RNPerfMetrics.ts',
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EdmondChuiHW consider adding front_end/global_typings/react_native.d.ts here as well in one of the next PRs.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. Looks like .d.ts are excluded somehow. The upstream file here doesn't have license and the linter doesn't complain.

Added ours to the list for clarity in #18

@EdmondChuiHW EdmondChuiHW mentioned this pull request Mar 12, 2024
2 tasks
This was referenced Mar 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants