Only measure "base" times within ProfileMode (#12821)
* Conditionally start/stop base timer only within Profile mode tree * Added test to ensure ProfilerTimer not called outside of Profiler root
This commit is contained in:
parent
9097f3cdf0
commit
103503eb69
|
@ -962,12 +962,17 @@ export default function<T, P, I, TI, HI, PI, C, CC, CX, PL>(
|
|||
|
||||
let next;
|
||||
if (enableProfilerTimer) {
|
||||
startBaseRenderTimer();
|
||||
if (workInProgress.mode & ProfileMode) {
|
||||
startBaseRenderTimer();
|
||||
}
|
||||
|
||||
next = beginWork(current, workInProgress, nextRenderExpirationTime);
|
||||
|
||||
// Update "base" time if the render wasn't bailed out on.
|
||||
recordElapsedBaseRenderTimeIfRunning(workInProgress);
|
||||
stopBaseRenderTimerIfRunning();
|
||||
if (workInProgress.mode & ProfileMode) {
|
||||
// Update "base" time if the render wasn't bailed out on.
|
||||
recordElapsedBaseRenderTimeIfRunning(workInProgress);
|
||||
stopBaseRenderTimerIfRunning();
|
||||
}
|
||||
} else {
|
||||
next = beginWork(current, workInProgress, nextRenderExpirationTime);
|
||||
}
|
||||
|
|
|
@ -108,10 +108,14 @@ describe('Profiler', () => {
|
|||
describe('onRender callback', () => {
|
||||
let AdvanceTime;
|
||||
let advanceTimeBy;
|
||||
let mockNow;
|
||||
|
||||
const mockNowForTests = () => {
|
||||
let currentTime = 0;
|
||||
ReactTestRenderer.unstable_setNowImplementation(() => currentTime);
|
||||
|
||||
mockNow = jest.fn().mockImplementation(() => currentTime);
|
||||
|
||||
ReactTestRenderer.unstable_setNowImplementation(mockNow);
|
||||
advanceTimeBy = amount => {
|
||||
currentTime += amount;
|
||||
};
|
||||
|
@ -164,6 +168,20 @@ describe('Profiler', () => {
|
|||
expect(callback).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('does not record times for components outside of Profiler tree', () => {
|
||||
ReactTestRenderer.create(
|
||||
<div>
|
||||
<AdvanceTime />
|
||||
<AdvanceTime />
|
||||
<AdvanceTime />
|
||||
</div>,
|
||||
);
|
||||
|
||||
// Should only be called twice, for normal expiration time purposes.
|
||||
// No additional calls from ProfilerTimer are expected.
|
||||
expect(mockNow).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it('logs render times for both mount and update', () => {
|
||||
const callback = jest.fn();
|
||||
|
||||
|
|
Loading…
Reference in New Issue