Make ReactPerf.start() work during reconciliation #7202
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently
ReactPerf.start()
andReactPerf.stop()
calls don’t work correctly during reconciliation.As far as I know this was occasionally the case before 15.x too—they weren’t working reliably.
Generally we advise that people call
ReactPerf
methods from the console but React components for this appears to be a popular pattern so it’s best we support it.I took the failing test from #7191 and built this PR on top of it.
This should fix the problem so people can write “measurer” components like this:
Why didn’t this work before? We used to only start and stop timers while
isProfiling
is true. However this doesn’t work correctly if the user flipsisProfiling
during reconciliation. Then we have mismatchingbegin
/end
timer calls.To fix this, I decided to always measure methods regardless of whether we are in profiling mode. I suppose calls to
performanceNow()
can’t be expensive, can they? And we are only doing this in__DEV__
anyway.The logic is changed so that we don’t record the measurements if
isProfiling
isfalse
. So we just make them and throw them away. This lets us avoid writing the logic to recover fromisProfiling
flipping in the middle of reconciliation.