Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ReactPerf.start() work during reconciliation #7202

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/renderers/shared/ReactDebugTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function resetMeasurements() {
var previousMeasurements = currentFlushMeasurements || [];
var previousOperations = ReactHostOperationHistoryDevtool.getHistory();

if (!isProfiling || currentFlushNesting === 0) {
if (currentFlushNesting === 0) {
currentFlushStartTime = null;
currentFlushMeasurements = null;
clearHistory();
Expand All @@ -106,7 +106,7 @@ function checkDebugID(debugID) {
}

function beginLifeCycleTimer(debugID, timerType) {
if (!isProfiling || currentFlushNesting === 0) {
if (currentFlushNesting === 0) {
return;
}
warning(
Expand All @@ -125,7 +125,7 @@ function beginLifeCycleTimer(debugID, timerType) {
}

function endLifeCycleTimer(debugID, timerType) {
if (!isProfiling || currentFlushNesting === 0) {
if (currentFlushNesting === 0) {
return;
}
warning(
Expand All @@ -137,11 +137,13 @@ function endLifeCycleTimer(debugID, timerType) {
currentTimerType || 'no',
(debugID === currentTimerDebugID) ? 'the same' : 'another'
);
currentFlushMeasurements.push({
timerType,
instanceID: debugID,
duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration,
});
if (isProfiling) {
currentFlushMeasurements.push({
timerType,
instanceID: debugID,
duration: performanceNow() - currentTimerStartTime - currentTimerNestedFlushDuration,
});
}
currentTimerStartTime = null;
currentTimerNestedFlushDuration = null;
currentTimerDebugID = null;
Expand Down
46 changes: 45 additions & 1 deletion src/renderers/shared/__tests__/ReactPerf-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,5 +467,49 @@ describe('ReactPerf', function() {
expect(console.error.calls.count()).toBe(1);

__DEV__ = true;
})
});

it('should work when measurement starts during reconciliation', () => {
// https://github.com/facebook/react/issues/6949#issuecomment-230371009
var Measurer = React.createClass({
componentWillMount() {
ReactPerf.start();
},
componentDidMount() {
ReactPerf.stop();
},
componentWillUpdate() {
ReactPerf.start();
},
componentDidUpdate() {
ReactPerf.stop();
},
render() {
// Force reconciliation despite constant element
return React.cloneElement(this.props.children);
},
});

var container = document.createElement('div');
ReactDOM.render(<Measurer><App /></Measurer>, container);
expect(ReactPerf.getWasted()).toEqual([]);

ReactDOM.render(<Measurer><App /></Measurer>, container);
expect(ReactPerf.getWasted()).toEqual([{
key: 'Measurer',
instanceCount: 1,
inclusiveRenderDuration: 4,
renderCount: 1,
}, {
key: 'App',
instanceCount: 1,
inclusiveRenderDuration: 3,
renderCount: 1,
}, {
key: 'App > Box',
instanceCount: 2,
inclusiveRenderDuration: 2,
renderCount: 2,
}]);
});
});