@@ -20,31 +20,64 @@ 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
29
56
// Create a mark on React initialization
30
57
if ( enableSchedulingProfiler ) {
31
- if ( supportsUserTiming ) {
32
- performance . mark ( `--react-init-${ ReactVersion } ` ) ;
58
+ if ( supportsUserTimingV3 ) {
59
+ const name = `--react-init-${ ReactVersion } ` ;
60
+ performance . mark ( name ) ;
61
+ performance . clearMarks ( name ) ;
33
62
}
34
63
}
35
64
36
65
export function markCommitStarted ( lanes : Lanes ) : void {
37
66
if ( enableSchedulingProfiler ) {
38
- if ( supportsUserTiming ) {
39
- performance . mark ( `--commit-start-${ formatLanes ( lanes ) } ` ) ;
67
+ if ( supportsUserTimingV3 ) {
68
+ const name = `--commit-start-${ formatLanes ( lanes ) } ` ;
69
+ performance . mark ( name ) ;
70
+ performance . clearMarks ( name ) ;
40
71
}
41
72
}
42
73
}
43
74
44
75
export function markCommitStopped ( ) : void {
45
76
if ( enableSchedulingProfiler ) {
46
- if ( supportsUserTiming ) {
47
- performance . mark ( '--commit-stop' ) ;
77
+ if ( supportsUserTimingV3 ) {
78
+ const name = '--commit-stop' ;
79
+ performance . mark ( name ) ;
80
+ performance . clearMarks ( name ) ;
48
81
}
49
82
}
50
83
}
@@ -63,103 +96,133 @@ function getWakeableID(wakeable: Wakeable): number {
63
96
64
97
export function markComponentSuspended ( fiber : Fiber , wakeable : Wakeable ) : void {
65
98
if ( enableSchedulingProfiler ) {
66
- if ( supportsUserTiming ) {
99
+ if ( supportsUserTimingV3 ) {
67
100
const id = getWakeableID ( wakeable ) ;
68
101
const componentName = getComponentName ( fiber . type ) || 'Unknown' ;
69
102
// TODO Add component stack id
70
- performance . mark ( `--suspense-suspend-${ id } -${ componentName } ` ) ;
103
+ let name = `--suspense-suspend-${ id } -${ componentName } ` ;
104
+ performance . mark ( name ) ;
105
+ performance . clearMarks ( name ) ;
71
106
wakeable . then (
72
- ( ) => performance . mark ( `--suspense-resolved-${ id } -${ componentName } ` ) ,
73
- ( ) => performance . mark ( `--suspense-rejected-${ id } -${ componentName } ` ) ,
107
+ ( ) => {
108
+ name = `--suspense-resolved-${ id } -${ componentName } ` ;
109
+ performance . mark ( name ) ;
110
+ performance . clearMarks ( name ) ;
111
+ } ,
112
+ ( ) => {
113
+ name = `--suspense-rejected-${ id } -${ componentName } ` ;
114
+ performance . mark ( name ) ;
115
+ performance . clearMarks ( name ) ;
116
+ } ,
74
117
) ;
75
118
}
76
119
}
77
120
}
78
121
79
122
export function markLayoutEffectsStarted ( lanes : Lanes ) : void {
80
123
if ( enableSchedulingProfiler ) {
81
- if ( supportsUserTiming ) {
82
- performance . mark ( `--layout-effects-start-${ formatLanes ( lanes ) } ` ) ;
124
+ if ( supportsUserTimingV3 ) {
125
+ const name = `-- layout - effects - start - $ { formatLanes ( lanes ) } `;
126
+ performance.mark(name);
127
+ performance.clearMarks(name);
83
128
}
84
129
}
85
130
}
86
131
87
132
export function markLayoutEffectsStopped(): void {
88
133
if (enableSchedulingProfiler) {
89
- if ( supportsUserTiming ) {
90
- performance . mark ( '--layout-effects-stop' ) ;
134
+ if (supportsUserTimingV3) {
135
+ const name = '--layout-effects-stop';
136
+ performance.mark(name);
137
+ performance.clearMarks(name);
91
138
}
92
139
}
93
140
}
94
141
95
142
export function markPassiveEffectsStarted(lanes: Lanes): void {
96
143
if (enableSchedulingProfiler) {
97
- if ( supportsUserTiming ) {
98
- performance . mark ( `--passive-effects-start-${ formatLanes ( lanes ) } ` ) ;
144
+ if (supportsUserTimingV3) {
145
+ const name = ` -- passive - effects - start - $ { formatLanes ( lanes ) } `;
146
+ performance.mark(name);
147
+ performance.clearMarks(name);
99
148
}
100
149
}
101
150
}
102
151
103
152
export function markPassiveEffectsStopped(): void {
104
153
if (enableSchedulingProfiler) {
105
- if ( supportsUserTiming ) {
106
- performance . mark ( '--passive-effects-stop' ) ;
154
+ if (supportsUserTimingV3) {
155
+ const name = '--passive-effects-stop';
156
+ performance.mark(name);
157
+ performance.clearMarks(name);
107
158
}
108
159
}
109
160
}
110
161
111
162
export function markRenderStarted(lanes: Lanes): void {
112
163
if (enableSchedulingProfiler) {
113
- if ( supportsUserTiming ) {
114
- performance . mark ( `--render-start-${ formatLanes ( lanes ) } ` ) ;
164
+ if (supportsUserTimingV3) {
165
+ const name = ` -- render - start - $ { formatLanes ( lanes ) } `;
166
+ performance.mark(name);
167
+ performance.clearMarks(name);
115
168
}
116
169
}
117
170
}
118
171
119
172
export function markRenderYielded(): void {
120
173
if (enableSchedulingProfiler) {
121
- if ( supportsUserTiming ) {
122
- performance . mark ( '--render-yield' ) ;
174
+ if (supportsUserTimingV3) {
175
+ const name = '--render-yield';
176
+ performance.mark(name);
177
+ performance.clearMarks(name);
123
178
}
124
179
}
125
180
}
126
181
127
182
export function markRenderStopped(): void {
128
183
if (enableSchedulingProfiler) {
129
- if ( supportsUserTiming ) {
130
- performance . mark ( '--render-stop' ) ;
184
+ if (supportsUserTimingV3) {
185
+ const name = '--render-stop';
186
+ performance.mark(name);
187
+ performance.clearMarks(name);
131
188
}
132
189
}
133
190
}
134
191
135
192
export function markRenderScheduled(lane: Lane): void {
136
193
if (enableSchedulingProfiler) {
137
- if ( supportsUserTiming ) {
138
- performance . mark ( `--schedule-render-${ formatLanes ( lane ) } ` ) ;
194
+ if (supportsUserTimingV3) {
195
+ const name = ` -- schedule - render - $ { formatLanes ( lane ) } `;
196
+ performance.mark(name);
197
+ performance.clearMarks(name);
139
198
}
140
199
}
141
200
}
142
201
143
202
export function markForceUpdateScheduled(fiber: Fiber, lane: Lane): void {
144
203
if (enableSchedulingProfiler) {
145
- if ( supportsUserTiming ) {
204
+ if (supportsUserTimingV3 ) {
146
205
const componentName = getComponentName(fiber.type) || 'Unknown';
147
206
// TODO Add component stack id
148
- performance . mark (
149
- `--schedule-forced-update-${ formatLanes ( lane ) } -${ componentName } ` ,
150
- ) ;
207
+ const name = ` -- schedule - forced - update - $ { formatLanes (
208
+ lane ,
209
+ ) } - $ { componentName} `;
210
+ performance.mark(name);
211
+ performance.clearMarks(name);
151
212
}
152
213
}
153
214
}
154
215
155
216
export function markStateUpdateScheduled(fiber: Fiber, lane: Lane): void {
156
217
if (enableSchedulingProfiler) {
157
- if ( supportsUserTiming ) {
218
+ if (supportsUserTimingV3 ) {
158
219
const componentName = getComponentName(fiber.type) || 'Unknown';
159
220
// TODO Add component stack id
160
- performance . mark (
161
- `--schedule-state-update-${ formatLanes ( lane ) } -${ componentName } ` ,
162
- ) ;
221
+ const name = ` -- schedule - state - update - $ { formatLanes (
222
+ lane ,
223
+ ) } - $ { componentName } `;
224
+ performance . mark ( name ) ;
225
+ performance . clearMarks ( name ) ;
163
226
}
164
227
}
165
228
}
0 commit comments