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

Only measure "base" times within ProfileMode #12821

Merged
merged 4 commits into from
May 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 19 additions & 1 deletion packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down Expand Up @@ -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();

Expand Down