@@ -20,31 +20,63 @@ import getComponentName from 'shared/getComponentName';
20
20
* require.
21
21
*/
22
22
const supportsUserTiming =
23
- typeof performance !== 'undefined' && typeof performance . mark === 'function' ;
23
+ typeof performance !== 'undefined' &&
24
+ typeof performance . mark === 'function' &&
25
+ typeof performance . clearMarks === 'function' ;
26
+
27
+ let supportsUserTimingV3 = false ;
28
+ if ( enableSchedulingProfiler ) {
29
+ if ( supportsUserTiming ) {
30
+ const CHECK_V3_MARK = '__v3' ;
31
+ const markOptions = { } ;
32
+ // $FlowFixMe: Ignore Flow complaining about needing a value
33
+ Object . defineProperty ( markOptions , 'startTime' , {
34
+ get : function ( ) {
35
+ supportsUserTimingV3 = true ;
36
+ return 0 ;
37
+ } ,
38
+ set : function ( ) { } ,
39
+ } ) ;
40
+
41
+ try {
42
+ // $FlowFixMe: Flow expects the User Timing level 2 API.
43
+ performance . mark ( CHECK_V3_MARK , markOptions ) ;
44
+ } catch ( error ) {
45
+ // Ignore
46
+ } finally {
47
+ performance . clearMarks ( CHECK_V3_MARK ) ;
48
+ }
49
+ }
50
+ }
24
51
25
52
function formatLanes ( laneOrLanes : Lane | Lanes ) : string {
26
53
return ( ( laneOrLanes : any ) : number ) . toString ( ) ;
27
54
}
28
55
56
+ function markAndClear ( name ) {
57
+ performance . mark ( name ) ;
58
+ performance . clearMarks ( name ) ;
59
+ }
60
+
29
61
// Create a mark on React initialization
30
62
if ( enableSchedulingProfiler ) {
31
- if ( supportsUserTiming ) {
32
- performance . mark ( `--react-init-${ ReactVersion } ` ) ;
63
+ if ( supportsUserTimingV3 ) {
64
+ markAndClear ( `--react-init-${ ReactVersion } ` ) ;
33
65
}
34
66
}
35
67
36
68
export function markCommitStarted ( lanes : Lanes ) : void {
37
69
if ( enableSchedulingProfiler ) {
38
- if ( supportsUserTiming ) {
39
- performance . mark ( `--commit-start-${ formatLanes ( lanes ) } ` ) ;
70
+ if ( supportsUserTimingV3 ) {
71
+ markAndClear ( `--commit-start-${ formatLanes ( lanes ) } ` ) ;
40
72
}
41
73
}
42
74
}
43
75
44
76
export function markCommitStopped ( ) : void {
45
77
if ( enableSchedulingProfiler ) {
46
- if ( supportsUserTiming ) {
47
- performance . mark ( '--commit-stop' ) ;
78
+ if ( supportsUserTimingV3 ) {
79
+ markAndClear ( '--commit-stop' ) ;
48
80
}
49
81
}
50
82
}
@@ -63,89 +95,89 @@ function getWakeableID(wakeable: Wakeable): number {
63
95
64
96
export function markComponentSuspended ( fiber : Fiber , wakeable : Wakeable ) : void {
65
97
if ( enableSchedulingProfiler ) {
66
- if ( supportsUserTiming ) {
98
+ if ( supportsUserTimingV3 ) {
67
99
const id = getWakeableID ( wakeable ) ;
68
100
const componentName = getComponentName ( fiber . type ) || 'Unknown' ;
69
101
// TODO Add component stack id
70
- performance . mark ( `--suspense-suspend-${ id } -${ componentName } ` ) ;
102
+ markAndClear ( `--suspense-suspend-${ id } -${ componentName } ` ) ;
71
103
wakeable . then (
72
- ( ) => performance . mark ( `--suspense-resolved-${ id } -${ componentName } ` ) ,
73
- ( ) => performance . mark ( `--suspense-rejected-${ id } -${ componentName } ` ) ,
104
+ ( ) => markAndClear ( `--suspense-resolved-${ id } -${ componentName } ` ) ,
105
+ ( ) => markAndClear ( `--suspense-rejected-${ id } -${ componentName } ` ) ,
74
106
) ;
75
107
}
76
108
}
77
109
}
78
110
79
111
export function markLayoutEffectsStarted ( lanes : Lanes ) : void {
80
112
if ( enableSchedulingProfiler ) {
81
- if ( supportsUserTiming ) {
82
- performance . mark ( `--layout-effects-start-${ formatLanes ( lanes ) } ` ) ;
113
+ if ( supportsUserTimingV3 ) {
114
+ markAndClear ( `--layout-effects-start-${ formatLanes ( lanes ) } ` ) ;
83
115
}
84
116
}
85
117
}
86
118
87
119
export function markLayoutEffectsStopped ( ) : void {
88
120
if ( enableSchedulingProfiler ) {
89
- if ( supportsUserTiming ) {
90
- performance . mark ( '--layout-effects-stop' ) ;
121
+ if ( supportsUserTimingV3 ) {
122
+ markAndClear ( '--layout-effects-stop' ) ;
91
123
}
92
124
}
93
125
}
94
126
95
127
export function markPassiveEffectsStarted ( lanes : Lanes ) : void {
96
128
if ( enableSchedulingProfiler ) {
97
- if ( supportsUserTiming ) {
98
- performance . mark ( `--passive-effects-start-${ formatLanes ( lanes ) } ` ) ;
129
+ if ( supportsUserTimingV3 ) {
130
+ markAndClear ( `--passive-effects-start-${ formatLanes ( lanes ) } ` ) ;
99
131
}
100
132
}
101
133
}
102
134
103
135
export function markPassiveEffectsStopped ( ) : void {
104
136
if ( enableSchedulingProfiler ) {
105
- if ( supportsUserTiming ) {
106
- performance . mark ( '--passive-effects-stop' ) ;
137
+ if ( supportsUserTimingV3 ) {
138
+ markAndClear ( '--passive-effects-stop' ) ;
107
139
}
108
140
}
109
141
}
110
142
111
143
export function markRenderStarted ( lanes : Lanes ) : void {
112
144
if ( enableSchedulingProfiler ) {
113
- if ( supportsUserTiming ) {
114
- performance . mark ( `--render-start-${ formatLanes ( lanes ) } ` ) ;
145
+ if ( supportsUserTimingV3 ) {
146
+ markAndClear ( `--render-start-${ formatLanes ( lanes ) } ` ) ;
115
147
}
116
148
}
117
149
}
118
150
119
151
export function markRenderYielded ( ) : void {
120
152
if ( enableSchedulingProfiler ) {
121
- if ( supportsUserTiming ) {
122
- performance . mark ( '--render-yield' ) ;
153
+ if ( supportsUserTimingV3 ) {
154
+ markAndClear ( '--render-yield' ) ;
123
155
}
124
156
}
125
157
}
126
158
127
159
export function markRenderStopped ( ) : void {
128
160
if ( enableSchedulingProfiler ) {
129
- if ( supportsUserTiming ) {
130
- performance . mark ( '--render-stop' ) ;
161
+ if ( supportsUserTimingV3 ) {
162
+ markAndClear ( '--render-stop' ) ;
131
163
}
132
164
}
133
165
}
134
166
135
167
export function markRenderScheduled ( lane : Lane ) : void {
136
168
if ( enableSchedulingProfiler ) {
137
- if ( supportsUserTiming ) {
138
- performance . mark ( `--schedule-render-${ formatLanes ( lane ) } ` ) ;
169
+ if ( supportsUserTimingV3 ) {
170
+ markAndClear ( `--schedule-render-${ formatLanes ( lane ) } ` ) ;
139
171
}
140
172
}
141
173
}
142
174
143
175
export function markForceUpdateScheduled ( fiber : Fiber , lane : Lane ) : void {
144
176
if ( enableSchedulingProfiler ) {
145
- if ( supportsUserTiming ) {
177
+ if ( supportsUserTimingV3 ) {
146
178
const componentName = getComponentName ( fiber . type ) || 'Unknown' ;
147
179
// TODO Add component stack id
148
- performance . mark (
180
+ markAndClear (
149
181
`--schedule-forced-update-${ formatLanes ( lane ) } -${ componentName } ` ,
150
182
) ;
151
183
}
@@ -154,10 +186,10 @@ export function markForceUpdateScheduled(fiber: Fiber, lane: Lane): void {
154
186
155
187
export function markStateUpdateScheduled ( fiber : Fiber , lane : Lane ) : void {
156
188
if ( enableSchedulingProfiler ) {
157
- if ( supportsUserTiming ) {
189
+ if ( supportsUserTimingV3 ) {
158
190
const componentName = getComponentName ( fiber . type ) || 'Unknown' ;
159
191
// TODO Add component stack id
160
- performance . mark (
192
+ markAndClear (
161
193
`--schedule-state-update-${ formatLanes ( lane ) } -${ componentName } ` ,
162
194
) ;
163
195
}
0 commit comments