Skip to content

Commit ecb9840

Browse files
huntiefacebook-github-bot
authored andcommitted
Add Performance Issues to Perf Monitor (1/2) (#54265)
Summary: Introduces the concept of **Performance Issues**, an experimental performance signals concept for React Native. **Design** Performance Issues are an **experimental** user space API via the User Timings `detail` object. ``` performance.measure({ start, end, detail: { devtools: { ... }, rnPerfIssue: { name: 'React: Cascading Update', severity: 'warning', // 'info' | 'warning' | 'error', description: 'A cascading update is a update that is triggered by a previous update. This can lead to performance issues and should be avoided.', learnMoreUrl: 'https://react.dev/reference/dev-tools/react-performance-tracks#cascading-updates', } } }); ``` When `rnPerfIssue` is present, we eagerly report an the event over CDP, regardless of an active performance trace, via the `"__react_native_perf_issues_reporter"` runtime binding. **This diff** - Adds a `perfIssuesEnabled` feature flag. - Initial implementation of the above API. - Initially reports a "Cascading Render" issue, aligning 1:1 with the corresponding React performance track event (note: to be added in the React codebase, see facebook/react#34961). This feature is gated by the `perfMonitorV2Enabled` feature flag. Changelog: [Internal] Differential Revision: D85448200
1 parent 6d68cdf commit ecb9840

29 files changed

+322
-74
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<3ea1ee77358d99334a7c40bed44f2d90>>
7+
* @generated SignedSource<<bac9e360daa589cba476d208f75ef2ca>>
88
*/
99

1010
/**
@@ -372,6 +372,12 @@ public object ReactNativeFeatureFlags {
372372
@JvmStatic
373373
public fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean = accessor.overrideBySynchronousMountPropsAtMountingAndroid()
374374

375+
/**
376+
* Enable reporting Performance Issues (`detail.rnPerfIssue`). Displayed in the V2 Performance Monitor and the "Performance Issues" sub-panel in DevTools.
377+
*/
378+
@JvmStatic
379+
public fun perfIssuesEnabled(): Boolean = accessor.perfIssuesEnabled()
380+
375381
/**
376382
* Enable the V2 in-app Performance Monitor. This flag is global and should not be changed across React Host lifetimes.
377383
*/

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<007a5a1235a999716b382ffd4ca23158>>
7+
* @generated SignedSource<<2003ae7fc2c782b997d21938cc7b2380>>
88
*/
99

1010
/**
@@ -77,6 +77,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
7777
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
7878
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
7979
private var overrideBySynchronousMountPropsAtMountingAndroidCache: Boolean? = null
80+
private var perfIssuesEnabledCache: Boolean? = null
8081
private var perfMonitorV2EnabledCache: Boolean? = null
8182
private var preparedTextCacheSizeCache: Double? = null
8283
private var preventShadowTreeCommitExhaustionCache: Boolean? = null
@@ -615,6 +616,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
615616
return cached
616617
}
617618

619+
override fun perfIssuesEnabled(): Boolean {
620+
var cached = perfIssuesEnabledCache
621+
if (cached == null) {
622+
cached = ReactNativeFeatureFlagsCxxInterop.perfIssuesEnabled()
623+
perfIssuesEnabledCache = cached
624+
}
625+
return cached
626+
}
627+
618628
override fun perfMonitorV2Enabled(): Boolean {
619629
var cached = perfMonitorV2EnabledCache
620630
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<8a775646d455cdb6d017fd08aee3e807>>
7+
* @generated SignedSource<<986b35ba4f323ab1a65dd70a559889e9>>
88
*/
99

1010
/**
@@ -142,6 +142,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
142142

143143
@DoNotStrip @JvmStatic public external fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean
144144

145+
@DoNotStrip @JvmStatic public external fun perfIssuesEnabled(): Boolean
146+
145147
@DoNotStrip @JvmStatic public external fun perfMonitorV2Enabled(): Boolean
146148

147149
@DoNotStrip @JvmStatic public external fun preparedTextCacheSize(): Double

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<afccaed3066598724041c48bfb524234>>
7+
* @generated SignedSource<<43f629e3be734826b241d7e596daf6f4>>
88
*/
99

1010
/**
@@ -137,6 +137,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
137137

138138
override fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean = false
139139

140+
override fun perfIssuesEnabled(): Boolean = false
141+
140142
override fun perfMonitorV2Enabled(): Boolean = false
141143

142144
override fun preparedTextCacheSize(): Double = 200.0

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ebeb9b37b8d3d0e31f4d4966cbf42b3f>>
7+
* @generated SignedSource<<806741418f4ff7e3b6dcac3d78fa27dd>>
88
*/
99

1010
/**
@@ -81,6 +81,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
8181
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
8282
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
8383
private var overrideBySynchronousMountPropsAtMountingAndroidCache: Boolean? = null
84+
private var perfIssuesEnabledCache: Boolean? = null
8485
private var perfMonitorV2EnabledCache: Boolean? = null
8586
private var preparedTextCacheSizeCache: Double? = null
8687
private var preventShadowTreeCommitExhaustionCache: Boolean? = null
@@ -676,6 +677,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
676677
return cached
677678
}
678679

680+
override fun perfIssuesEnabled(): Boolean {
681+
var cached = perfIssuesEnabledCache
682+
if (cached == null) {
683+
cached = currentProvider.perfIssuesEnabled()
684+
accessedFeatureFlags.add("perfIssuesEnabled")
685+
perfIssuesEnabledCache = cached
686+
}
687+
return cached
688+
}
689+
679690
override fun perfMonitorV2Enabled(): Boolean {
680691
var cached = perfMonitorV2EnabledCache
681692
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<1c4ea60d119996f37742542976fedcc8>>
7+
* @generated SignedSource<<1a08578b36cb91a183a435b881ca272f>>
88
*/
99

1010
/**
@@ -137,6 +137,8 @@ public interface ReactNativeFeatureFlagsProvider {
137137

138138
@DoNotStrip public fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean
139139

140+
@DoNotStrip public fun perfIssuesEnabled(): Boolean
141+
140142
@DoNotStrip public fun perfMonitorV2Enabled(): Boolean
141143

142144
@DoNotStrip public fun preparedTextCacheSize(): Double

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d04720bbbd42eaf338be612a0f3e36a6>>
7+
* @generated SignedSource<<4c22217e5a773fd97f4041ef6e052ebc>>
88
*/
99

1010
/**
@@ -381,6 +381,12 @@ class ReactNativeFeatureFlagsJavaProvider
381381
return method(javaProvider_);
382382
}
383383

384+
bool perfIssuesEnabled() override {
385+
static const auto method =
386+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("perfIssuesEnabled");
387+
return method(javaProvider_);
388+
}
389+
384390
bool perfMonitorV2Enabled() override {
385391
static const auto method =
386392
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("perfMonitorV2Enabled");
@@ -814,6 +820,11 @@ bool JReactNativeFeatureFlagsCxxInterop::overrideBySynchronousMountPropsAtMounti
814820
return ReactNativeFeatureFlags::overrideBySynchronousMountPropsAtMountingAndroid();
815821
}
816822

823+
bool JReactNativeFeatureFlagsCxxInterop::perfIssuesEnabled(
824+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
825+
return ReactNativeFeatureFlags::perfIssuesEnabled();
826+
}
827+
817828
bool JReactNativeFeatureFlagsCxxInterop::perfMonitorV2Enabled(
818829
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
819830
return ReactNativeFeatureFlags::perfMonitorV2Enabled();
@@ -1136,6 +1147,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
11361147
makeNativeMethod(
11371148
"overrideBySynchronousMountPropsAtMountingAndroid",
11381149
JReactNativeFeatureFlagsCxxInterop::overrideBySynchronousMountPropsAtMountingAndroid),
1150+
makeNativeMethod(
1151+
"perfIssuesEnabled",
1152+
JReactNativeFeatureFlagsCxxInterop::perfIssuesEnabled),
11391153
makeNativeMethod(
11401154
"perfMonitorV2Enabled",
11411155
JReactNativeFeatureFlagsCxxInterop::perfMonitorV2Enabled),

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<7679a91daba1f8941b78a4be4baea6ef>>
7+
* @generated SignedSource<<91f5bbbab5f34321687c6f6d31ca49d8>>
88
*/
99

1010
/**
@@ -201,6 +201,9 @@ class JReactNativeFeatureFlagsCxxInterop
201201
static bool overrideBySynchronousMountPropsAtMountingAndroid(
202202
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
203203

204+
static bool perfIssuesEnabled(
205+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
206+
204207
static bool perfMonitorV2Enabled(
205208
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
206209

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<303e8208cbdf0b9b9041942822c5597d>>
7+
* @generated SignedSource<<91ecd61e5e2ed1a15248db4e40993018>>
88
*/
99

1010
/**
@@ -254,6 +254,10 @@ bool ReactNativeFeatureFlags::overrideBySynchronousMountPropsAtMountingAndroid()
254254
return getAccessor().overrideBySynchronousMountPropsAtMountingAndroid();
255255
}
256256

257+
bool ReactNativeFeatureFlags::perfIssuesEnabled() {
258+
return getAccessor().perfIssuesEnabled();
259+
}
260+
257261
bool ReactNativeFeatureFlags::perfMonitorV2Enabled() {
258262
return getAccessor().perfMonitorV2Enabled();
259263
}

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<07b665ad842faafaf7520051f636d805>>
7+
* @generated SignedSource<<e996f8acef4c9feeda40ea920a2e5353>>
88
*/
99

1010
/**
@@ -324,6 +324,11 @@ class ReactNativeFeatureFlags {
324324
*/
325325
RN_EXPORT static bool overrideBySynchronousMountPropsAtMountingAndroid();
326326

327+
/**
328+
* Enable reporting Performance Issues (`detail.rnPerfIssue`). Displayed in the V2 Performance Monitor and the "Performance Issues" sub-panel in DevTools.
329+
*/
330+
RN_EXPORT static bool perfIssuesEnabled();
331+
327332
/**
328333
* Enable the V2 in-app Performance Monitor. This flag is global and should not be changed across React Host lifetimes.
329334
*/

0 commit comments

Comments
 (0)