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

Adjust SuspenseList CPU bound heuristic #17455

Merged
merged 2 commits into from
Dec 3, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -2358,6 +2358,7 @@ function initSuspenseListRenderState(
workInProgress.memoizedState = ({
isBackwards: isBackwards,
rendering: null,
renderingStartTime: 0,
last: lastContentRow,
tail: tail,
tailExpiration: 0,
Expand All @@ -2368,6 +2369,7 @@ function initSuspenseListRenderState(
// We can reuse the existing object from previous renders.
renderState.isBackwards = isBackwards;
renderState.rendering = null;
renderState.renderingStartTime = 0;
renderState.last = lastContentRow;
renderState.tail = tail;
renderState.tailExpiration = 0;
Expand Down
12 changes: 11 additions & 1 deletion packages/react-reconciler/src/ReactFiberCompleteWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,10 @@ function completeWork(
return null;
}
} else if (
now() > renderState.tailExpiration &&
// The time it took to render last row is greater than time until
// the expiration.
now() * 2 - renderState.renderingStartTime >
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline comment that translates this into English plz

"The time it took to render last row is greater than time until the expiration"

renderState.tailExpiration &&
renderExpirationTime > Never
) {
// We have now passed our CPU deadline and we'll just give up further
Expand Down Expand Up @@ -1164,12 +1167,19 @@ function completeWork(
// until we just give up and show what we have so far.
const TAIL_EXPIRATION_TIMEOUT_MS = 500;
renderState.tailExpiration = now() + TAIL_EXPIRATION_TIMEOUT_MS;
// TODO: This is meant to mimic the train model or JND but this
// is a per component value. It should really be since the start
// of the total render or last commit. Consider using something like
// globalMostRecentFallbackTime. That doesn't account for being
// suspended for part of the time or when it's a new render.
// It should probably use a global start time value instead.
}
// Pop a row.
let next = renderState.tail;
renderState.rendering = next;
renderState.tail = next.sibling;
renderState.lastEffect = workInProgress.lastEffect;
renderState.renderingStartTime = now();
next.sibling = null;

// Restore the context.
Expand Down
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactFiberSuspenseComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export type SuspenseListRenderState = {|
isBackwards: boolean,
// The currently rendering tail row.
rendering: null | Fiber,
// The absolute time when we started rendering the tail row.
renderingStartTime: number,
// The last of the already rendered children.
last: null | Fiber,
// Remaining rows on the tail of the list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1233,8 +1233,8 @@ describe('ReactSuspenseList', () => {

expect(Scheduler).toFlushAndYieldThrough(['A']);

Scheduler.unstable_advanceTime(300);
jest.advanceTimersByTime(300);
Scheduler.unstable_advanceTime(200);
jest.advanceTimersByTime(200);

expect(Scheduler).toFlushAndYieldThrough(['B']);

Expand Down Expand Up @@ -1407,8 +1407,8 @@ describe('ReactSuspenseList', () => {

expect(Scheduler).toFlushAndYieldThrough(['A']);

Scheduler.unstable_advanceTime(300);
jest.advanceTimersByTime(300);
Scheduler.unstable_advanceTime(200);
jest.advanceTimersByTime(200);

expect(Scheduler).toFlushAndYieldThrough(['B']);

Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/__tests__/ReactDOMTracing-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -561,8 +561,8 @@ describe('ReactDOMTracing', () => {

expect(Scheduler).toFlushAndYieldThrough(['A']);

Scheduler.unstable_advanceTime(300);
jest.advanceTimersByTime(300);
Scheduler.unstable_advanceTime(200);
jest.advanceTimersByTime(200);

expect(Scheduler).toFlushAndYieldThrough(['B']);

Expand Down