Skip to content

Commit

Permalink
Perf: Static children count for wasted time
Browse files Browse the repository at this point in the history
  • Loading branch information
sophiebits committed Nov 4, 2015
1 parent 4ba0e95 commit 5d94d7d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/test/ReactDefaultPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
26 changes: 24 additions & 2 deletions src/test/__tests__/ReactDefaultPerf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
},
});

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5d94d7d

Please sign in to comment.