@@ -20,31 +20,63 @@ import getComponentName from 'shared/getComponentName';
2020 * require. 
2121 */ 
2222const  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+ } 
2451
2552function  formatLanes ( laneOrLanes : Lane  |  Lanes ) : string  { 
2653  return  ( ( laneOrLanes : any ) : number ) . toString ( ) ; 
2754} 
2855
56+ function  markAndClear ( name )  { 
57+   performance . mark ( name ) ; 
58+   performance . clearMarks ( name ) ; 
59+ } 
60+ 
2961// Create a mark on React initialization 
3062if  ( enableSchedulingProfiler )  { 
31-   if  ( supportsUserTiming )  { 
32-     performance . mark ( `--react-init-${ ReactVersion }  ` ) ; 
63+   if  ( supportsUserTimingV3 )  { 
64+     markAndClear ( `--react-init-${ ReactVersion }  ` ) ; 
3365  } 
3466} 
3567
3668export  function  markCommitStarted ( lanes : Lanes ) : void  { 
3769  if  ( enableSchedulingProfiler )  { 
38-     if  ( supportsUserTiming )  { 
39-       performance . mark ( `--commit-start-${ formatLanes ( lanes ) }  ` ) ; 
70+     if  ( supportsUserTimingV3 )  { 
71+       markAndClear ( `--commit-start-${ formatLanes ( lanes ) }  ` ) ; 
4072    } 
4173  } 
4274} 
4375
4476export  function  markCommitStopped ( ) : void  { 
4577  if  ( enableSchedulingProfiler )  { 
46-     if  ( supportsUserTiming )  { 
47-       performance . mark ( '--commit-stop' ) ; 
78+     if  ( supportsUserTimingV3 )  { 
79+       markAndClear ( '--commit-stop' ) ; 
4880    } 
4981  } 
5082} 
@@ -63,89 +95,89 @@ function getWakeableID(wakeable: Wakeable): number {
6395
6496export  function  markComponentSuspended ( fiber : Fiber ,  wakeable : Wakeable ) : void  { 
6597  if  ( enableSchedulingProfiler )  { 
66-     if  ( supportsUserTiming )  { 
98+     if  ( supportsUserTimingV3 )  { 
6799      const  id  =  getWakeableID ( wakeable ) ; 
68100      const  componentName  =  getComponentName ( fiber . type )  ||  'Unknown' ; 
69101      // TODO Add component stack id 
70-       performance . mark ( `--suspense-suspend-${ id }  -${ componentName }  ` ) ; 
102+       markAndClear ( `--suspense-suspend-${ id }  -${ componentName }  ` ) ; 
71103      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 }  ` ) , 
74106      ) ; 
75107    } 
76108  } 
77109} 
78110
79111export  function  markLayoutEffectsStarted ( lanes : Lanes ) : void  { 
80112  if  ( enableSchedulingProfiler )  { 
81-     if  ( supportsUserTiming )  { 
82-       performance . mark ( `--layout-effects-start-${ formatLanes ( lanes ) }  ` ) ; 
113+     if  ( supportsUserTimingV3 )  { 
114+       markAndClear ( `--layout-effects-start-${ formatLanes ( lanes ) }  ` ) ; 
83115    } 
84116  } 
85117} 
86118
87119export  function  markLayoutEffectsStopped ( ) : void  { 
88120  if  ( enableSchedulingProfiler )  { 
89-     if  ( supportsUserTiming )  { 
90-       performance . mark ( '--layout-effects-stop' ) ; 
121+     if  ( supportsUserTimingV3 )  { 
122+       markAndClear ( '--layout-effects-stop' ) ; 
91123    } 
92124  } 
93125} 
94126
95127export  function  markPassiveEffectsStarted ( lanes : Lanes ) : void  { 
96128  if  ( enableSchedulingProfiler )  { 
97-     if  ( supportsUserTiming )  { 
98-       performance . mark ( `--passive-effects-start-${ formatLanes ( lanes ) }  ` ) ; 
129+     if  ( supportsUserTimingV3 )  { 
130+       markAndClear ( `--passive-effects-start-${ formatLanes ( lanes ) }  ` ) ; 
99131    } 
100132  } 
101133} 
102134
103135export  function  markPassiveEffectsStopped ( ) : void  { 
104136  if  ( enableSchedulingProfiler )  { 
105-     if  ( supportsUserTiming )  { 
106-       performance . mark ( '--passive-effects-stop' ) ; 
137+     if  ( supportsUserTimingV3 )  { 
138+       markAndClear ( '--passive-effects-stop' ) ; 
107139    } 
108140  } 
109141} 
110142
111143export  function  markRenderStarted ( lanes : Lanes ) : void  { 
112144  if  ( enableSchedulingProfiler )  { 
113-     if  ( supportsUserTiming )  { 
114-       performance . mark ( `--render-start-${ formatLanes ( lanes ) }  ` ) ; 
145+     if  ( supportsUserTimingV3 )  { 
146+       markAndClear ( `--render-start-${ formatLanes ( lanes ) }  ` ) ; 
115147    } 
116148  } 
117149} 
118150
119151export  function  markRenderYielded ( ) : void  { 
120152  if  ( enableSchedulingProfiler )  { 
121-     if  ( supportsUserTiming )  { 
122-       performance . mark ( '--render-yield' ) ; 
153+     if  ( supportsUserTimingV3 )  { 
154+       markAndClear ( '--render-yield' ) ; 
123155    } 
124156  } 
125157} 
126158
127159export  function  markRenderStopped ( ) : void  { 
128160  if  ( enableSchedulingProfiler )  { 
129-     if  ( supportsUserTiming )  { 
130-       performance . mark ( '--render-stop' ) ; 
161+     if  ( supportsUserTimingV3 )  { 
162+       markAndClear ( '--render-stop' ) ; 
131163    } 
132164  } 
133165} 
134166
135167export  function  markRenderScheduled ( lane : Lane ) : void  { 
136168  if  ( enableSchedulingProfiler )  { 
137-     if  ( supportsUserTiming )  { 
138-       performance . mark ( `--schedule-render-${ formatLanes ( lane ) }  ` ) ; 
169+     if  ( supportsUserTimingV3 )  { 
170+       markAndClear ( `--schedule-render-${ formatLanes ( lane ) }  ` ) ; 
139171    } 
140172  } 
141173} 
142174
143175export  function  markForceUpdateScheduled ( fiber : Fiber ,  lane : Lane ) : void  { 
144176  if  ( enableSchedulingProfiler )  { 
145-     if  ( supportsUserTiming )  { 
177+     if  ( supportsUserTimingV3 )  { 
146178      const  componentName  =  getComponentName ( fiber . type )  ||  'Unknown' ; 
147179      // TODO Add component stack id 
148-       performance . mark ( 
180+       markAndClear ( 
149181        `--schedule-forced-update-${ formatLanes ( lane ) }  -${ componentName }  ` , 
150182      ) ; 
151183    } 
@@ -154,10 +186,10 @@ export function markForceUpdateScheduled(fiber: Fiber, lane: Lane): void {
154186
155187export  function  markStateUpdateScheduled ( fiber : Fiber ,  lane : Lane ) : void  { 
156188  if  ( enableSchedulingProfiler )  { 
157-     if  ( supportsUserTiming )  { 
189+     if  ( supportsUserTimingV3 )  { 
158190      const  componentName  =  getComponentName ( fiber . type )  ||  'Unknown' ; 
159191      // TODO Add component stack id 
160-       performance . mark ( 
192+       markAndClear ( 
161193        `--schedule-state-update-${ formatLanes ( lane ) }  -${ componentName }  ` , 
162194      ) ; 
163195    } 
0 commit comments