Skip to content

Commit 4b9d2e9

Browse files
huntiefacebook-github-bot
authored andcommitted
Add Performance Issues to Perf Monitor (1/2) (facebook#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 c029032 commit 4b9d2e9

30 files changed

+361
-85
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<<28000f9d4a36207875619060f2fa5713>>
7+
* @generated SignedSource<<42f1d3335bdb130144d2c68a74052cab>>
88
*/
99

1010
/**
@@ -366,6 +366,12 @@ public object ReactNativeFeatureFlags {
366366
@JvmStatic
367367
public fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean = accessor.overrideBySynchronousMountPropsAtMountingAndroid()
368368

369+
/**
370+
* Enable reporting Performance Issues (`detail.rnPerfIssue`). Displayed in the V2 Performance Monitor and the "Performance Issues" sub-panel in DevTools.
371+
*/
372+
@JvmStatic
373+
public fun perfIssuesEnabled(): Boolean = accessor.perfIssuesEnabled()
374+
369375
/**
370376
* Enable the V2 in-app Performance Monitor. This flag is global and should not be changed across React Host lifetimes.
371377
*/

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<<ba1a322a9c7069cf63fd759090f9025d>>
7+
* @generated SignedSource<<dce2cc27b4a53efb01d361be1ab6ed4c>>
88
*/
99

1010
/**
@@ -76,6 +76,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
7676
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
7777
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
7878
private var overrideBySynchronousMountPropsAtMountingAndroidCache: Boolean? = null
79+
private var perfIssuesEnabledCache: Boolean? = null
7980
private var perfMonitorV2EnabledCache: Boolean? = null
8081
private var preparedTextCacheSizeCache: Double? = null
8182
private var preventShadowTreeCommitExhaustionCache: Boolean? = null
@@ -605,6 +606,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
605606
return cached
606607
}
607608

609+
override fun perfIssuesEnabled(): Boolean {
610+
var cached = perfIssuesEnabledCache
611+
if (cached == null) {
612+
cached = ReactNativeFeatureFlagsCxxInterop.perfIssuesEnabled()
613+
perfIssuesEnabledCache = cached
614+
}
615+
return cached
616+
}
617+
608618
override fun perfMonitorV2Enabled(): Boolean {
609619
var cached = perfMonitorV2EnabledCache
610620
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<<412a865e975214a0d794985e48fbbe4b>>
7+
* @generated SignedSource<<a75099156524d7f42c7def64d123901a>>
88
*/
99

1010
/**
@@ -140,6 +140,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
140140

141141
@DoNotStrip @JvmStatic public external fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean
142142

143+
@DoNotStrip @JvmStatic public external fun perfIssuesEnabled(): Boolean
144+
143145
@DoNotStrip @JvmStatic public external fun perfMonitorV2Enabled(): Boolean
144146

145147
@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<<7987eba84c39c6e8cb6494092a94790e>>
7+
* @generated SignedSource<<a8ea071d5392313bcc4f8c7e9dc3e29a>>
88
*/
99

1010
/**
@@ -135,6 +135,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
135135

136136
override fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean = false
137137

138+
override fun perfIssuesEnabled(): Boolean = false
139+
138140
override fun perfMonitorV2Enabled(): Boolean = false
139141

140142
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<<7f43cde1ba2bef2300c077f35b168d31>>
7+
* @generated SignedSource<<b5b44845d08744627ab9cd32a36df881>>
88
*/
99

1010
/**
@@ -80,6 +80,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
8080
private var fuseboxNetworkInspectionEnabledCache: Boolean? = null
8181
private var hideOffscreenVirtualViewsOnIOSCache: Boolean? = null
8282
private var overrideBySynchronousMountPropsAtMountingAndroidCache: Boolean? = null
83+
private var perfIssuesEnabledCache: Boolean? = null
8384
private var perfMonitorV2EnabledCache: Boolean? = null
8485
private var preparedTextCacheSizeCache: Double? = null
8586
private var preventShadowTreeCommitExhaustionCache: Boolean? = null
@@ -665,6 +666,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
665666
return cached
666667
}
667668

669+
override fun perfIssuesEnabled(): Boolean {
670+
var cached = perfIssuesEnabledCache
671+
if (cached == null) {
672+
cached = currentProvider.perfIssuesEnabled()
673+
accessedFeatureFlags.add("perfIssuesEnabled")
674+
perfIssuesEnabledCache = cached
675+
}
676+
return cached
677+
}
678+
668679
override fun perfMonitorV2Enabled(): Boolean {
669680
var cached = perfMonitorV2EnabledCache
670681
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<<692dcdb2af3c6af981e8f48686ca105e>>
7+
* @generated SignedSource<<5971ef1d8501ceda0aa9d7254f8655d4>>
88
*/
99

1010
/**
@@ -135,6 +135,8 @@ public interface ReactNativeFeatureFlagsProvider {
135135

136136
@DoNotStrip public fun overrideBySynchronousMountPropsAtMountingAndroid(): Boolean
137137

138+
@DoNotStrip public fun perfIssuesEnabled(): Boolean
139+
138140
@DoNotStrip public fun perfMonitorV2Enabled(): Boolean
139141

140142
@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<<48a05f5360c927150021af873e6d52b8>>
7+
* @generated SignedSource<<c2025e0cf674d83e6af8d78d8f45b6a9>>
88
*/
99

1010
/**
@@ -375,6 +375,12 @@ class ReactNativeFeatureFlagsJavaProvider
375375
return method(javaProvider_);
376376
}
377377

378+
bool perfIssuesEnabled() override {
379+
static const auto method =
380+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("perfIssuesEnabled");
381+
return method(javaProvider_);
382+
}
383+
378384
bool perfMonitorV2Enabled() override {
379385
static const auto method =
380386
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("perfMonitorV2Enabled");
@@ -803,6 +809,11 @@ bool JReactNativeFeatureFlagsCxxInterop::overrideBySynchronousMountPropsAtMounti
803809
return ReactNativeFeatureFlags::overrideBySynchronousMountPropsAtMountingAndroid();
804810
}
805811

812+
bool JReactNativeFeatureFlagsCxxInterop::perfIssuesEnabled(
813+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
814+
return ReactNativeFeatureFlags::perfIssuesEnabled();
815+
}
816+
806817
bool JReactNativeFeatureFlagsCxxInterop::perfMonitorV2Enabled(
807818
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
808819
return ReactNativeFeatureFlags::perfMonitorV2Enabled();
@@ -1122,6 +1133,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
11221133
makeNativeMethod(
11231134
"overrideBySynchronousMountPropsAtMountingAndroid",
11241135
JReactNativeFeatureFlagsCxxInterop::overrideBySynchronousMountPropsAtMountingAndroid),
1136+
makeNativeMethod(
1137+
"perfIssuesEnabled",
1138+
JReactNativeFeatureFlagsCxxInterop::perfIssuesEnabled),
11251139
makeNativeMethod(
11261140
"perfMonitorV2Enabled",
11271141
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<<e8bbe1de8eccb3ecea6b9f001de07fd2>>
7+
* @generated SignedSource<<ec58172a1cf44747c32a6f9d9e34b1ce>>
88
*/
99

1010
/**
@@ -198,6 +198,9 @@ class JReactNativeFeatureFlagsCxxInterop
198198
static bool overrideBySynchronousMountPropsAtMountingAndroid(
199199
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
200200

201+
static bool perfIssuesEnabled(
202+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
203+
201204
static bool perfMonitorV2Enabled(
202205
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
203206

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<<0554340092d31b5431e201f570599ab5>>
7+
* @generated SignedSource<<8d5f7122ca675380250ae4bd95fb3751>>
88
*/
99

1010
/**
@@ -250,6 +250,10 @@ bool ReactNativeFeatureFlags::overrideBySynchronousMountPropsAtMountingAndroid()
250250
return getAccessor().overrideBySynchronousMountPropsAtMountingAndroid();
251251
}
252252

253+
bool ReactNativeFeatureFlags::perfIssuesEnabled() {
254+
return getAccessor().perfIssuesEnabled();
255+
}
256+
253257
bool ReactNativeFeatureFlags::perfMonitorV2Enabled() {
254258
return getAccessor().perfMonitorV2Enabled();
255259
}

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<<98a77cdecfd3e6d42f03b2b4ba3d8c88>>
7+
* @generated SignedSource<<86e886f737f1662df981ecc19c456800>>
88
*/
99

1010
/**
@@ -319,6 +319,11 @@ class ReactNativeFeatureFlags {
319319
*/
320320
RN_EXPORT static bool overrideBySynchronousMountPropsAtMountingAndroid();
321321

322+
/**
323+
* Enable reporting Performance Issues (`detail.rnPerfIssue`). Displayed in the V2 Performance Monitor and the "Performance Issues" sub-panel in DevTools.
324+
*/
325+
RN_EXPORT static bool perfIssuesEnabled();
326+
322327
/**
323328
* Enable the V2 in-app Performance Monitor. This flag is global and should not be changed across React Host lifetimes.
324329
*/

0 commit comments

Comments
 (0)