Perf: Static children count for wasted time
Ben Alpert committed
Oct 18, 2015 at 14:21 UTC
5d94d7d43c1804db4e6de2a89036fa63cea3a518
2 files changed
+27
-2
src/test/ReactDefaultPerf.js
+3
@@ -205,6 +205,9 @@ var ReactDefaultPerf = {
205
var id = args[0];
206
if (moduleName === 'EventPluginHub') {
207
id = id._rootNodeID;
208
+ } else if (fnName === 'replaceNodeWithMarkup') {
209
+ // Old node is already unmounted; can't get its instance
210
+ id = ReactDOMComponentTree.getInstanceFromNode(args[1].node)._rootNodeID;
211
} else if (typeof id === 'object') {
212
id = ReactDOMComponentTree.getInstanceFromNode(args[0])._rootNodeID;
213
}
src/test/__tests__/ReactDefaultPerf-test.js
+24
-2
@@ -36,13 +36,13 @@ describe('ReactDefaultPerf', function() {
36
37
App = React.createClass({
38
render: function() {
39
- return <div><Box /><Box /></div>;
39
+ return <div><Box /><Box flip={this.props.flipSecond} /></div>;
40
},
41
});
42
43
Box = React.createClass({
44
render: function() {
45
- return <div><input /></div>;
45
+ return <div key={!!this.props.flip}><input /></div>;
46
},
47
});
48
@@ -84,6 +84,28 @@ describe('ReactDefaultPerf', function() {
84
/*eslint-enable dot-notation */
85
});
86
87
+ it('should count no-op update in child as waste', function() {
88
+ var container = document.createElement('div');
89
+ ReactDOM.render(<App />, container);
90
+
91
+ // Here, we add a Box -- two of the <Box /> updates are wasted time (but the
92
+ // addition of the third is not)
93
+ var measurements = measure(() => {
94
+ ReactDOM.render(<App flipSecond={true} />, container);
95
+ });
96
+
97
+ var summary = ReactDefaultPerf.getMeasurementsSummaryMap(measurements);
98
+ expect(summary.length).toBe(1);
99
+
100
+ /*eslint-disable dot-notation */
101
+
102
+ expect(summary[0]['Owner > component']).toBe('App > Box');
103
+ expect(summary[0]['Wasted time (ms)']).not.toBe(0);
104
+ expect(summary[0]['Instances']).toBe(1);
105
+
106
+ /*eslint-enable dot-notation */
107
+ });
108
+
109
function expectNoWaste(fn) {
110
var measurements = measure(fn);
111
var summary = ReactDefaultPerf.getMeasurementsSummaryMap(measurements);