From 25326d4a907b4db823dcee1a1a293841d5a5ce6f Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 12 Aug 2021 14:01:14 -1000 Subject: [PATCH 01/11] Setup metrics --- package-lock.json | 5 ++++ package.json | 1 + src/CONFIG.js | 1 + src/libs/Performance.js | 44 ++++++++++++++++++++++++++++++- src/libs/actions/App.js | 7 +++++ src/pages/settings/InitialPage.js | 8 ++++++ src/setup/index.native.js | 4 +++ 7 files changed, 69 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 745f32d27bc1..8731bee7675a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -36169,6 +36169,11 @@ "prop-types": "^15.7.2" } }, + "react-native-performance": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/react-native-performance/-/react-native-performance-2.0.0.tgz", + "integrity": "sha512-jKM9Qg0SkL9D9ad377nxb1VV+OXJSyYyIrBHKmM6CABNxfrLVA5xkQMEibjmZQde7b0ndJOZoQAiObgJjjc4VQ==" + }, "react-native-permissions": { "version": "3.0.1", "resolved": "https://registry.npmjs.org/react-native-permissions/-/react-native-permissions-3.0.1.tgz", diff --git a/package.json b/package.json index c7b9aec25855..91f257b40024 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "react-native-modal": "^11.10.0", "react-native-onyx": "git+https://github.com/Expensify/react-native-onyx.git#d7553b95e982ab78f6bb2064f6b0549f0ace94c2", "react-native-pdf": "^6.2.2", + "react-native-performance": "^2.0.0", "react-native-permissions": "^3.0.1", "react-native-picker-select": "8.0.4", "react-native-plaid-link-sdk": "^7.0.5", diff --git a/src/CONFIG.js b/src/CONFIG.js index b43cbc0309c7..2b6a840690b6 100644 --- a/src/CONFIG.js +++ b/src/CONFIG.js @@ -60,4 +60,5 @@ export default { DEFAULT: '/favicon.png', UNREAD: '/favicon-unread.png', }, + CAPTURE_METRICS: lodashGet(Config, 'CAPTURE_METRICS', false), }; diff --git a/src/libs/Performance.js b/src/libs/Performance.js index f391c706b998..176cdd6201f4 100644 --- a/src/libs/Performance.js +++ b/src/libs/Performance.js @@ -1,5 +1,6 @@ import _ from 'underscore'; import lodashTransform from 'lodash/transform'; +import CONFIG from '../CONFIG'; /** * Deep diff between two objects. Useful for figuring out what changed about an object from one render to the next so @@ -24,7 +25,48 @@ function diffObject(object, base) { return changes(object, base); } +/** + * Enables capturing performance stats. + * + * @returns {Boolean} + */ +function canCapturePerformanceMetrics() { + return CONFIG.CAPTURE_METRICS; +} + +function setupPerformanceObserver() { + if (!canCapturePerformanceMetrics()) { + return; + } + + const performance = require('react-native-performance').default; + const PerformanceObserver = require('react-native-performance').PerformanceObserver; + new PerformanceObserver((list) => { + if (list.getEntries().find(entry => entry.name === 'nativeLaunchEnd')) { + performance.measure('nativeLaunch', 'nativeLaunchStart', 'nativeLaunchEnd'); + + // eslint-disable-next-line no-undef + if (__DEV__) { + performance.measure('jsBundleDownload', 'downloadStart', 'downloadEnd'); + } else { + performance.measure('runJsBundle', 'runJsBundleStart', 'runJsBundleEnd'); + } + } + }).observe({type: 'react-native-mark', buffered: true}); +} + +/** + * Outputs performance stats. We alert these so that they are easy to access in release builds. + */ +function printPerformanceMetrics() { + const performance = require('react-native-performance').default; + const entries = _.map(performance.getEntriesByType('measure'), entry => ({name: entry.name, duration: Math.floor(entry.duration)})); + alert(JSON.stringify(entries, null, 4)); +} + export { - // eslint-disable-next-line import/prefer-default-export diffObject, + canCapturePerformanceMetrics, + printPerformanceMetrics, + setupPerformanceObserver, }; diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index cad9bcce3e23..b9ee5a86c037 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -7,6 +7,7 @@ import CONST from '../../CONST'; import CONFIG from '../../CONFIG'; import Firebase from '../Firebase'; import ROUTES from '../../ROUTES'; +import {canCapturePerformanceMetrics} from '../Performance'; let currentUserAccountID; Onyx.connect({ @@ -58,6 +59,12 @@ function setSidebarLoaded() { Onyx.set(ONYXKEYS.IS_SIDEBAR_LOADED, true); Firebase.stopTrace(CONST.TIMING.SIDEBAR_LOADED); + + if (canCapturePerformanceMetrics()) { + const performance = require('react-native-performance').default; + performance.mark('sidebarLoadEnd'); + performance.measure('launchToSidebarLoad', 'nativeLaunchStart', 'sidebarLoadEnd'); + } } export { diff --git a/src/pages/settings/InitialPage.js b/src/pages/settings/InitialPage.js index ca3774b4cd91..999b805e0902 100755 --- a/src/pages/settings/InitialPage.js +++ b/src/pages/settings/InitialPage.js @@ -27,6 +27,7 @@ import ROUTES from '../../ROUTES'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; import compose from '../../libs/compose'; import CONST from '../../CONST'; +import {canCapturePerformanceMetrics, printPerformanceMetrics} from '../../libs/Performance'; const propTypes = { /* Onyx Props */ @@ -119,6 +120,13 @@ const defaultMenuItems = [ }, ]; +if (canCapturePerformanceMetrics()) { + defaultMenuItems.unshift({ + title: 'Print Perf Metrics', + action: () => printPerformanceMetrics(), + }); +} + const InitialSettingsPage = ({ myPersonalDetails, network, diff --git a/src/setup/index.native.js b/src/setup/index.native.js index 3e6e8990599d..e2c92bd9108d 100644 --- a/src/setup/index.native.js +++ b/src/setup/index.native.js @@ -1,3 +1,5 @@ +import {setupPerformanceObserver} from '../libs/Performance'; + // Setup Flipper plugins when on dev export default function () { // eslint-disable-next-line no-undef @@ -7,4 +9,6 @@ export default function () { const AsyncStorage = require('@react-native-async-storage/async-storage').default; RNAsyncStorageFlipper(AsyncStorage); } + + setupPerformanceObserver(); } From 49a89fb931cdfafb27b4c371fe1161ae90e949da Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 12 Aug 2021 14:07:03 -1000 Subject: [PATCH 02/11] Add tool to measure app start time --- src/libs/Performance.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libs/Performance.js b/src/libs/Performance.js index 176cdd6201f4..b8a55b0e657f 100644 --- a/src/libs/Performance.js +++ b/src/libs/Performance.js @@ -34,6 +34,9 @@ function canCapturePerformanceMetrics() { return CONFIG.CAPTURE_METRICS; } +/** + * Sets up an observer to capture events recorded in the native layer before the app fully initializes. + */ function setupPerformanceObserver() { if (!canCapturePerformanceMetrics()) { return; @@ -60,7 +63,9 @@ function setupPerformanceObserver() { */ function printPerformanceMetrics() { const performance = require('react-native-performance').default; - const entries = _.map(performance.getEntriesByType('measure'), entry => ({name: entry.name, duration: Math.floor(entry.duration)})); + const entries = _.map(performance.getEntriesByType('measure'), entry => ({ + name: entry.name, duration: Math.floor(entry.duration), + })); alert(JSON.stringify(entries, null, 4)); } From 3616eec0284ea9a14af34dce958bf3962eb31b4f Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 12 Aug 2021 15:03:57 -1000 Subject: [PATCH 03/11] Update pod --- ios/Podfile.lock | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 02d3ed08d31b..3f434d1f589b 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -420,6 +420,8 @@ PODS: - React-Core - react-native-pdf (6.2.2): - React-Core + - react-native-performance (2.0.0): + - React-Core - react-native-plaid-link-sdk (7.0.5): - Plaid (~> 2.1.2) - React-Core @@ -638,6 +640,7 @@ DEPENDENCIES: - react-native-image-picker (from `../node_modules/react-native-image-picker`) - "react-native-netinfo (from `../node_modules/@react-native-community/netinfo`)" - react-native-pdf (from `../node_modules/react-native-pdf`) + - react-native-performance (from `../node_modules/react-native-performance/ios`) - react-native-plaid-link-sdk (from `../node_modules/react-native-plaid-link-sdk`) - "react-native-progress-bar-android (from `../node_modules/@react-native-community/progress-bar-android`)" - "react-native-progress-view (from `../node_modules/@react-native-community/progress-view`)" @@ -772,6 +775,8 @@ EXTERNAL SOURCES: :path: "../node_modules/@react-native-community/netinfo" react-native-pdf: :path: "../node_modules/react-native-pdf" + react-native-performance: + :path: "../node_modules/react-native-performance/ios" react-native-plaid-link-sdk: :path: "../node_modules/react-native-plaid-link-sdk" react-native-progress-bar-android: @@ -872,7 +877,7 @@ SPEC CHECKSUMS: DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de EXHaptics: 337c160c148baa6f0e7166249f368965906e346b FBLazyVector: 7b423f9e248eae65987838148c36eec1dbfe0b53 - FBReactNativeSpec: c783a75db87c963c60afcd461fc38358805fe5ba + FBReactNativeSpec: 884d4cc2b011759361797a4035c47e10099393b5 Firebase: 54cdc8bc9c9b3de54f43dab86e62f5a76b47034f FirebaseABTesting: 4cb61aeeb50f60680af1c01fff781dfaf9293916 FirebaseAnalytics: 4751d6a49598a2b58da678cc07df696bcd809ab9 @@ -922,6 +927,7 @@ SPEC CHECKSUMS: react-native-image-picker: 4089335b89b625d4e34d53fb249c48a7a791b3ea react-native-netinfo: 52cf0ee8342548a485e28f4b09e56b477567244d react-native-pdf: 4b5a9e4465a6a3b399e91dc4838eb44ddf716d1f + react-native-performance: 8edfa2bbc9a2af4a02f01d342118e413a95145e0 react-native-plaid-link-sdk: 1a6593e2d3d790e8113c29178d883eb883f8c032 react-native-progress-bar-android: ce95a69f11ac580799021633071368d08aaf9ad8 react-native-progress-view: 5816e8a6be812c2b122c6225a2a3db82d9008640 From 1b5483522fc17bd2c616c56e3783fd5b39629d71 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 12 Aug 2021 15:15:58 -1000 Subject: [PATCH 04/11] early return --- src/libs/Performance.js | 2 +- src/libs/actions/App.js | 10 ++++++---- src/pages/settings/InitialPage.js | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/libs/Performance.js b/src/libs/Performance.js index b8a55b0e657f..d9eb770ebad2 100644 --- a/src/libs/Performance.js +++ b/src/libs/Performance.js @@ -31,7 +31,7 @@ function diffObject(object, base) { * @returns {Boolean} */ function canCapturePerformanceMetrics() { - return CONFIG.CAPTURE_METRICS; + return Boolean(CONFIG.CAPTURE_METRICS); } /** diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index b9ee5a86c037..601790447dae 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -60,11 +60,13 @@ function setSidebarLoaded() { Onyx.set(ONYXKEYS.IS_SIDEBAR_LOADED, true); Firebase.stopTrace(CONST.TIMING.SIDEBAR_LOADED); - if (canCapturePerformanceMetrics()) { - const performance = require('react-native-performance').default; - performance.mark('sidebarLoadEnd'); - performance.measure('launchToSidebarLoad', 'nativeLaunchStart', 'sidebarLoadEnd'); + if (!canCapturePerformanceMetrics()) { + return; } + + const performance = require('react-native-performance').default; + performance.mark('sidebarLoadEnd'); + performance.measure('timeToInteractive', 'nativeLaunchStart', 'sidebarLoadEnd'); } export { diff --git a/src/pages/settings/InitialPage.js b/src/pages/settings/InitialPage.js index 999b805e0902..2e6f6e7e8e51 100755 --- a/src/pages/settings/InitialPage.js +++ b/src/pages/settings/InitialPage.js @@ -120,6 +120,7 @@ const defaultMenuItems = [ }, ]; +// Add the print metrics option to the Settings menu if it is enabled if (canCapturePerformanceMetrics()) { defaultMenuItems.unshift({ title: 'Print Perf Metrics', From 6720393bed033c3f939ec5d3d4739edb0dbb0aae Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 12 Aug 2021 15:29:16 -1000 Subject: [PATCH 05/11] Add tips to Performance docs --- PERFORMANCE.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/PERFORMANCE.md b/PERFORMANCE.md index 192e76e0dd67..dd59cdcd37de 100644 --- a/PERFORMANCE.md +++ b/PERFORMANCE.md @@ -27,12 +27,39 @@ ### Why Did You Render? - Why Did You Render (WDYR) sends console notifications about potentially avoidable component re-renders. - It can also help to simply track when and why a certain component re-renders. -- To enable it, set `USE_WDYR=true` in your `.env` file. +- To enable it, set `USE_WDYR=true` in your `.env` file. - You can add or exclude tracked components by their `displayName` in `wdyr.js`. - Open the browser console to see WDYR notifications. **Suggested** [Why Did You Render docs](https://github.com/welldone-software/why-did-you-render) +### Performance Metrics (Opt-In on local release builds) + +It's not particularly straightforward to capture and output metrics in release builds. However, one could argue that the metrics in release builds are the only truly reliable metrics to use for native platforms. To make this easier for everyone to do we created an opt-in tool (using `react-native-performance`) that will capture metrics and add a new menu option to display them in the Settings page. To set this up just set `CAPTURE_METRICS=true` in your `.env` file then create a release build on iOS or Android. The metrics this tool shows are as follows: + +- `nativeLaunch` - Total time for the native process to intialize +- `runJSBundle` - Total time to parse and execute the JS bundle +- `timeToInteractive` - Roughly tracks the total overall time (starting with the native init and ending with the sidebar UI load) + +#### How to create a Release Build on Android + +- Create a keystore by running `keytool -genkey -v -keystore your_key_name.keystore -alias your_key_alias -keyalg RSA -keysize 2048 -validity 10000` +- Fill out all the prompts with any info and give it a password +- Drag the generated keystore to `/android/app` +- Hardcode the values to the gradle config like so: + +``` +signingConfigs { + release { + storeFile file('your_key_name.keystore') + storePassword 'Password1' + keyAlias 'your_key_alias' + keyPassword 'Password1' + } +``` +- Delete any existing apps off emulator or device +- Run `react-native run-android --variant release` + ## Reconciliation React is pretty smart and in many cases is able to tell if something needs to update. The process by which React goes about updating the "tree" or view heirarchy is called reconciliation. If React thinks something needs to update it will render it again. React also assumes that if a parent component rendered then it's child should also re-render. From fb181b50db2dd3b6665116723aa8742c8506e136 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Thu, 12 Aug 2021 15:44:22 -1000 Subject: [PATCH 06/11] Fix doc --- PERFORMANCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PERFORMANCE.md b/PERFORMANCE.md index dd59cdcd37de..22d17cc497a7 100644 --- a/PERFORMANCE.md +++ b/PERFORMANCE.md @@ -35,7 +35,7 @@ ### Performance Metrics (Opt-In on local release builds) -It's not particularly straightforward to capture and output metrics in release builds. However, one could argue that the metrics in release builds are the only truly reliable metrics to use for native platforms. To make this easier for everyone to do we created an opt-in tool (using `react-native-performance`) that will capture metrics and add a new menu option to display them in the Settings page. To set this up just set `CAPTURE_METRICS=true` in your `.env` file then create a release build on iOS or Android. The metrics this tool shows are as follows: +To capture reliable performance metrics for native app launch we must test against a release build. To make this easier for everyone to do we created an opt-in tool (using [`react-native-performance`](https://github.com/oblador/react-native-performance) that will capture metrics and add a new menu option to display them in the Settings page. To set this up just set `CAPTURE_METRICS=true` in your `.env` file then create a release build on iOS or Android. The metrics this tool shows are as follows: - `nativeLaunch` - Total time for the native process to intialize - `runJSBundle` - Total time to parse and execute the JS bundle From cea2820787a6692e6bd47f15a380db80022d69f3 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 13 Aug 2021 06:27:06 -1000 Subject: [PATCH 07/11] just pop alert for now --- src/libs/actions/App.js | 3 ++- src/pages/settings/InitialPage.js | 9 --------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 601790447dae..7c06565aae11 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -7,7 +7,7 @@ import CONST from '../../CONST'; import CONFIG from '../../CONFIG'; import Firebase from '../Firebase'; import ROUTES from '../../ROUTES'; -import {canCapturePerformanceMetrics} from '../Performance'; +import {canCapturePerformanceMetrics, printPerformanceMetrics} from '../Performance'; let currentUserAccountID; Onyx.connect({ @@ -67,6 +67,7 @@ function setSidebarLoaded() { const performance = require('react-native-performance').default; performance.mark('sidebarLoadEnd'); performance.measure('timeToInteractive', 'nativeLaunchStart', 'sidebarLoadEnd'); + printPerformanceMetrics(); } export { diff --git a/src/pages/settings/InitialPage.js b/src/pages/settings/InitialPage.js index 2e6f6e7e8e51..ca3774b4cd91 100755 --- a/src/pages/settings/InitialPage.js +++ b/src/pages/settings/InitialPage.js @@ -27,7 +27,6 @@ import ROUTES from '../../ROUTES'; import withLocalize, {withLocalizePropTypes} from '../../components/withLocalize'; import compose from '../../libs/compose'; import CONST from '../../CONST'; -import {canCapturePerformanceMetrics, printPerformanceMetrics} from '../../libs/Performance'; const propTypes = { /* Onyx Props */ @@ -120,14 +119,6 @@ const defaultMenuItems = [ }, ]; -// Add the print metrics option to the Settings menu if it is enabled -if (canCapturePerformanceMetrics()) { - defaultMenuItems.unshift({ - title: 'Print Perf Metrics', - action: () => printPerformanceMetrics(), - }); -} - const InitialSettingsPage = ({ myPersonalDetails, network, From e937b6b76c3bcafbf40f98e68e08b92aebbc5c62 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 13 Aug 2021 06:29:27 -1000 Subject: [PATCH 08/11] fix docs --- PERFORMANCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PERFORMANCE.md b/PERFORMANCE.md index 22d17cc497a7..010cfc30211c 100644 --- a/PERFORMANCE.md +++ b/PERFORMANCE.md @@ -35,7 +35,7 @@ ### Performance Metrics (Opt-In on local release builds) -To capture reliable performance metrics for native app launch we must test against a release build. To make this easier for everyone to do we created an opt-in tool (using [`react-native-performance`](https://github.com/oblador/react-native-performance) that will capture metrics and add a new menu option to display them in the Settings page. To set this up just set `CAPTURE_METRICS=true` in your `.env` file then create a release build on iOS or Android. The metrics this tool shows are as follows: +To capture reliable performance metrics for native app launch we must test against a release build. To make this easier for everyone to do we created an opt-in tool (using [`react-native-performance`](https://github.com/oblador/react-native-performance) that will capture metrics and display them in an alert once the app becomes interactive. To set this up just set `CAPTURE_METRICS=true` in your `.env` file then create a release build on iOS or Android. The metrics this tool shows are as follows: - `nativeLaunch` - Total time for the native process to intialize - `runJSBundle` - Total time to parse and execute the JS bundle From 2e5489edc24aebade495c194042f1fd2deeaf131 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 13 Aug 2021 06:32:55 -1000 Subject: [PATCH 09/11] fix comment --- PERFORMANCE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PERFORMANCE.md b/PERFORMANCE.md index 010cfc30211c..2763ad1d38ac 100644 --- a/PERFORMANCE.md +++ b/PERFORMANCE.md @@ -39,7 +39,7 @@ To capture reliable performance metrics for native app launch we must test again - `nativeLaunch` - Total time for the native process to intialize - `runJSBundle` - Total time to parse and execute the JS bundle -- `timeToInteractive` - Roughly tracks the total overall time (starting with the native init and ending with the sidebar UI load) +- `timeToInteractive` - Rough TTI (Time to Interactive). Includes native init time + sidebar UI partially loaded #### How to create a Release Build on Android From 8f4f6ed8abe4fe9e9b52900f6e02a63f93f69336 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 13 Aug 2021 07:10:59 -1000 Subject: [PATCH 10/11] add param to example env --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index 499a17fd916c..d884526f76df 100644 --- a/.env.example +++ b/.env.example @@ -9,3 +9,4 @@ NGROK_URL=https://expensify-user.ngrok.io/ USE_NGROK=false USE_WEB_PROXY=false USE_WDYR=false +CAPTURE_METRICS=false From d52fd83026622955c9b23947ba2371b399e2aa70 Mon Sep 17 00:00:00 2001 From: Marc Glasser Date: Fri, 13 Aug 2021 07:30:01 -1000 Subject: [PATCH 11/11] do not capture metrics on web --- src/libs/Performance.js | 12 +----------- src/libs/actions/App.js | 3 ++- src/libs/canCapturePerformanceMetrics/index.js | 2 ++ .../canCapturePerformanceMetrics/index.native.js | 10 ++++++++++ 4 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 src/libs/canCapturePerformanceMetrics/index.js create mode 100644 src/libs/canCapturePerformanceMetrics/index.native.js diff --git a/src/libs/Performance.js b/src/libs/Performance.js index d9eb770ebad2..ba6805fd2e57 100644 --- a/src/libs/Performance.js +++ b/src/libs/Performance.js @@ -1,6 +1,6 @@ import _ from 'underscore'; import lodashTransform from 'lodash/transform'; -import CONFIG from '../CONFIG'; +import canCapturePerformanceMetrics from './canCapturePerformanceMetrics'; /** * Deep diff between two objects. Useful for figuring out what changed about an object from one render to the next so @@ -25,15 +25,6 @@ function diffObject(object, base) { return changes(object, base); } -/** - * Enables capturing performance stats. - * - * @returns {Boolean} - */ -function canCapturePerformanceMetrics() { - return Boolean(CONFIG.CAPTURE_METRICS); -} - /** * Sets up an observer to capture events recorded in the native layer before the app fully initializes. */ @@ -71,7 +62,6 @@ function printPerformanceMetrics() { export { diffObject, - canCapturePerformanceMetrics, printPerformanceMetrics, setupPerformanceObserver, }; diff --git a/src/libs/actions/App.js b/src/libs/actions/App.js index 7c06565aae11..dcab886f39b2 100644 --- a/src/libs/actions/App.js +++ b/src/libs/actions/App.js @@ -7,7 +7,8 @@ import CONST from '../../CONST'; import CONFIG from '../../CONFIG'; import Firebase from '../Firebase'; import ROUTES from '../../ROUTES'; -import {canCapturePerformanceMetrics, printPerformanceMetrics} from '../Performance'; +import {printPerformanceMetrics} from '../Performance'; +import canCapturePerformanceMetrics from '../canCapturePerformanceMetrics'; let currentUserAccountID; Onyx.connect({ diff --git a/src/libs/canCapturePerformanceMetrics/index.js b/src/libs/canCapturePerformanceMetrics/index.js new file mode 100644 index 000000000000..1dc112f46dec --- /dev/null +++ b/src/libs/canCapturePerformanceMetrics/index.js @@ -0,0 +1,2 @@ +// We don't capture performance metrics on web as there are enough tools available +export default () => false; diff --git a/src/libs/canCapturePerformanceMetrics/index.native.js b/src/libs/canCapturePerformanceMetrics/index.native.js new file mode 100644 index 000000000000..a324c28a607c --- /dev/null +++ b/src/libs/canCapturePerformanceMetrics/index.native.js @@ -0,0 +1,10 @@ +import CONFIG from '../../CONFIG'; + +/** + * Enables capturing performance stats. + * + * @returns {Boolean} + */ +export default function canCapturePerformanceMetrics() { + return Boolean(CONFIG.CAPTURE_METRICS); +}