Perf: Static children count for wasted time

This commit is contained in:
Ben Alpert committed 2015-11-04 11:39:43 -08:00
1 parent 4ba0e95a96
commit 5d94d7d43c
2 files changed
+27 -2

No files matched your search

+3
View File
@@ -205,6 +205,9 @@ var ReactDefaultPerf = {
var id = args[0];
if (moduleName === 'EventPluginHub') {
id = id._rootNodeID;
} else if (fnName === 'replaceNodeWithMarkup') {
// Old node is already unmounted; can't get its instance
id = ReactDOMComponentTree.getInstanceFromNode(args[1].node)._rootNodeID;
} else if (typeof id === 'object') {
id = ReactDOMComponentTree.getInstanceFromNode(args[0])._rootNodeID;
}
+24 -2
View File
@@ -36,13 +36,13 @@ describe('ReactDefaultPerf', function() {
App = React.createClass({
render: function() {
return <div><Box /><Box /></div>;
return <div><Box /><Box flip={this.props.flipSecond} /></div>;
},
});
Box = React.createClass({
render: function() {
return <div><input /></div>;
return <div key={!!this.props.flip}><input /></div>;
},
});
@@ -84,6 +84,28 @@ describe('ReactDefaultPerf', function() {
/*eslint-enable dot-notation */
});
it('should count no-op update in child as waste', function() {
var container = document.createElement('div');
ReactDOM.render(<App />, container);
// Here, we add a Box -- two of the <Box /> updates are wasted time (but the
// addition of the third is not)
var measurements = measure(() => {
ReactDOM.render(<App flipSecond={true} />, container);
});
var summary = ReactDefaultPerf.getMeasurementsSummaryMap(measurements);
expect(summary.length).toBe(1);
/*eslint-disable dot-notation */
expect(summary[0]['Owner > component']).toBe('App > Box');
expect(summary[0]['Wasted time (ms)']).not.toBe(0);
expect(summary[0]['Instances']).toBe(1);
/*eslint-enable dot-notation */
});
function expectNoWaste(fn) {
var measurements = measure(fn);
var summary = ReactDefaultPerf.getMeasurementsSummaryMap(measurements);