@@ -28,9 +28,26 @@ function addValue(obj, key, val) {
2828 obj [ key ] = ( obj [ key ] || 0 ) + val ;
2929}
3030
31+ // Composites don't have any built-in ID: we have to make our own
32+ var compositeIDMap ;
33+ var compositeIDCounter = 17000 ;
34+ function getIDOfComposite ( inst ) {
35+ if ( ! compositeIDMap ) {
36+ compositeIDMap = new WeakMap ( ) ;
37+ }
38+ if ( compositeIDMap . has ( inst ) ) {
39+ return compositeIDMap . get ( inst ) ;
40+ } else {
41+ var id = compositeIDCounter ++ ;
42+ compositeIDMap . set ( inst , id ) ;
43+ return id ;
44+ }
45+ }
46+
3147var ReactDefaultPerf = {
3248 _allMeasurements : [ ] , // last item in the list is the current one
3349 _mountStack : [ 0 ] ,
50+ _compositeStack : [ ] ,
3451 _injected : false ,
3552
3653 start : function ( ) {
@@ -125,10 +142,10 @@ var ReactDefaultPerf = {
125142
126143 _recordWrite : function ( id , fnName , totalTime , args ) {
127144 // TODO: totalTime isn't that useful since it doesn't count paints/reflows
128- var writes =
145+ var entry =
129146 ReactDefaultPerf
130- . _allMeasurements [ ReactDefaultPerf . _allMeasurements . length - 1 ]
131- . writes ;
147+ . _allMeasurements [ ReactDefaultPerf . _allMeasurements . length - 1 ] ;
148+ var writes = entry . writes ;
132149 writes [ id ] = writes [ id ] || [ ] ;
133150 writes [ id ] . push ( {
134151 type : fnName ,
@@ -143,27 +160,30 @@ var ReactDefaultPerf = {
143160 var rv ;
144161 var start ;
145162
163+ var entry = ReactDefaultPerf . _allMeasurements [
164+ ReactDefaultPerf . _allMeasurements . length - 1
165+ ] ;
166+
146167 if ( fnName === '_renderNewRootComponent' ||
147168 fnName === 'flushBatchedUpdates' ) {
148169 // A "measurement" is a set of metrics recorded for each flush. We want
149170 // to group the metrics for a given flush together so we can look at the
150171 // components that rendered and the DOM operations that actually
151172 // happened to determine the amount of "wasted work" performed.
152- ReactDefaultPerf . _allMeasurements . push ( {
173+ ReactDefaultPerf . _allMeasurements . push ( entry = {
153174 exclusive : { } ,
154175 inclusive : { } ,
155176 render : { } ,
156177 counts : { } ,
157178 writes : { } ,
158179 displayNames : { } ,
180+ hierarchy : { } ,
159181 totalTime : 0 ,
160182 created : { } ,
161183 } ) ;
162184 start = performanceNow ( ) ;
163185 rv = func . apply ( this , args ) ;
164- ReactDefaultPerf . _allMeasurements [
165- ReactDefaultPerf . _allMeasurements . length - 1
166- ] . totalTime = performanceNow ( ) - start ;
186+ entry . totalTime = performanceNow ( ) - start ;
167187 return rv ;
168188 } else if ( fnName === '_mountImageIntoNode' ||
169189 moduleName === 'ReactDOMIDOperations' ||
@@ -228,16 +248,11 @@ var ReactDefaultPerf = {
228248 return func . apply ( this , args ) ;
229249 }
230250
231- var rootNodeID = fnName === 'mountComponent' ?
232- args [ 0 ] :
233- this . _rootNodeID ;
251+ var rootNodeID = getIDOfComposite ( this ) ;
234252 var isRender = fnName === '_renderValidatedComponent' ;
235253 var isMount = fnName === 'mountComponent' ;
236254
237255 var mountStack = ReactDefaultPerf . _mountStack ;
238- var entry = ReactDefaultPerf . _allMeasurements [
239- ReactDefaultPerf . _allMeasurements . length - 1
240- ] ;
241256
242257 if ( isRender ) {
243258 addValue ( entry . counts , rootNodeID , 1 ) ;
@@ -246,10 +261,14 @@ var ReactDefaultPerf = {
246261 mountStack . push ( 0 ) ;
247262 }
248263
264+ ReactDefaultPerf . _compositeStack . push ( rootNodeID ) ;
265+
249266 start = performanceNow ( ) ;
250267 rv = func . apply ( this , args ) ;
251268 totalTime = performanceNow ( ) - start ;
252269
270+ ReactDefaultPerf . _compositeStack . pop ( ) ;
271+
253272 if ( isRender ) {
254273 addValue ( entry . render , rootNodeID , totalTime ) ;
255274 } else if ( isMount ) {
@@ -269,6 +288,16 @@ var ReactDefaultPerf = {
269288 } ;
270289
271290 return rv ;
291+ } else if (
292+ ( moduleName === 'ReactDOMComponent' ||
293+ moduleName === 'ReactDOMTextComponent' ) &&
294+ ( fnName === 'mountComponent' ||
295+ fnName === 'receiveComponent' ) ) {
296+
297+ rv = func . apply ( this , args ) ;
298+ entry . hierarchy [ this . _rootNodeID ] =
299+ ReactDefaultPerf . _compositeStack . slice ( ) ;
300+ return rv ;
272301 } else {
273302 return func . apply ( this , args ) ;
274303 }
0 commit comments