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 NoWork big instead of small #13904

Closed
wants to merge 2 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
14 changes: 3 additions & 11 deletions packages/react-reconciler/src/ReactFiberBeginWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,7 @@ function updatePureComponent(
) {
const render = Component.render;

if (
current !== null &&
(updateExpirationTime === NoWork ||
updateExpirationTime > renderExpirationTime)
) {
if (current !== null && updateExpirationTime > renderExpirationTime) {
const prevProps = current.memoizedProps;
// Default to shallow comparison
let compare = Component.compare;
Expand Down Expand Up @@ -1351,10 +1347,7 @@ function bailoutOnAlreadyFinishedWork(

// Check if the children have any pending work.
const childExpirationTime = workInProgress.childExpirationTime;
if (
childExpirationTime === NoWork ||
childExpirationTime > renderExpirationTime
) {
if (childExpirationTime > renderExpirationTime) {
// The children don't have any work either. We can skip them.
// TODO: Once we add back resuming, we should check if the children are
// a work-in-progress set. If so, we need to transfer their effects.
Expand All @@ -1380,8 +1373,7 @@ function beginWork(
if (
oldProps === newProps &&
!hasLegacyContextChanged() &&
(updateExpirationTime === NoWork ||
updateExpirationTime > renderExpirationTime)
updateExpirationTime > renderExpirationTime
) {
// This fiber does not have any pending work. Bailout without entering
// the begin phase. There's still some bookkeeping we that needs to be done
Expand Down
4 changes: 2 additions & 2 deletions packages/react-reconciler/src/ReactFiberExpirationTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import MAX_SIGNED_31_BIT_INT from './maxSigned31BitInt';

export type ExpirationTime = number;

export const NoWork = 0;
export const NoWork = MAX_SIGNED_31_BIT_INT;
export const Sync = 1;
export const Never = MAX_SIGNED_31_BIT_INT;
export const Never = MAX_SIGNED_31_BIT_INT - 1;

const UNIT_SIZE = 10;
const MAGIC_NUMBER_OFFSET = 2;
Expand Down
19 changes: 5 additions & 14 deletions packages/react-reconciler/src/ReactFiberNewContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,17 +177,13 @@ export function propagateContextChange(
enqueueUpdate(fiber, update);
}

if (
fiber.expirationTime === NoWork ||
fiber.expirationTime > renderExpirationTime
) {
if (fiber.expirationTime > renderExpirationTime) {
fiber.expirationTime = renderExpirationTime;
}
let alternate = fiber.alternate;
if (
alternate !== null &&
(alternate.expirationTime === NoWork ||
alternate.expirationTime > renderExpirationTime)
alternate.expirationTime > renderExpirationTime
) {
alternate.expirationTime = renderExpirationTime;
}
Expand All @@ -196,22 +192,17 @@ export function propagateContextChange(
let node = fiber.return;
while (node !== null) {
alternate = node.alternate;
if (
node.childExpirationTime === NoWork ||
node.childExpirationTime > renderExpirationTime
) {
if (node.childExpirationTime > renderExpirationTime) {
node.childExpirationTime = renderExpirationTime;
if (
alternate !== null &&
(alternate.childExpirationTime === NoWork ||
alternate.childExpirationTime > renderExpirationTime)
alternate.childExpirationTime > renderExpirationTime
) {
alternate.childExpirationTime = renderExpirationTime;
}
} else if (
alternate !== null &&
(alternate.childExpirationTime === NoWork ||
alternate.childExpirationTime > renderExpirationTime)
alternate.childExpirationTime > renderExpirationTime
) {
alternate.childExpirationTime = renderExpirationTime;
} else {
Expand Down
18 changes: 3 additions & 15 deletions packages/react-reconciler/src/ReactFiberPendingPriority.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,18 +225,10 @@ export function findEarliestOutstandingPriorityLevel(

const earliestPendingTime = root.earliestPendingTime;
const earliestSuspendedTime = root.earliestSuspendedTime;
if (
earliestExpirationTime === NoWork ||
(earliestPendingTime !== NoWork &&
earliestPendingTime < earliestExpirationTime)
) {
if (earliestPendingTime < earliestExpirationTime) {
earliestExpirationTime = earliestPendingTime;
}
if (
earliestExpirationTime === NoWork ||
(earliestSuspendedTime !== NoWork &&
earliestSuspendedTime < earliestExpirationTime)
) {
if (earliestSuspendedTime < earliestExpirationTime) {
earliestExpirationTime = earliestSuspendedTime;
}
return earliestExpirationTime;
Expand Down Expand Up @@ -278,11 +270,7 @@ function findNextExpirationTimeToWorkOn(completedExpirationTime, root) {
}

let expirationTime = nextExpirationTimeToWorkOn;
if (
expirationTime !== NoWork &&
earliestSuspendedTime !== NoWork &&
earliestSuspendedTime < expirationTime
) {
if (expirationTime !== NoWork && earliestSuspendedTime < expirationTime) {
// Expire using the earliest known expiration time.
expirationTime = earliestSuspendedTime;
}
Expand Down
80 changes: 20 additions & 60 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,9 +556,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
const updateExpirationTimeBeforeCommit = finishedWork.expirationTime;
const childExpirationTimeBeforeCommit = finishedWork.childExpirationTime;
const earliestRemainingTimeBeforeCommit =
updateExpirationTimeBeforeCommit === NoWork ||
(childExpirationTimeBeforeCommit !== NoWork &&
childExpirationTimeBeforeCommit < updateExpirationTimeBeforeCommit)
childExpirationTimeBeforeCommit < updateExpirationTimeBeforeCommit
? childExpirationTimeBeforeCommit
: updateExpirationTimeBeforeCommit;
markCommittedPriorityLevels(root, earliestRemainingTimeBeforeCommit);
Expand Down Expand Up @@ -733,9 +731,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
const updateExpirationTimeAfterCommit = finishedWork.expirationTime;
const childExpirationTimeAfterCommit = finishedWork.childExpirationTime;
const earliestRemainingTimeAfterCommit =
updateExpirationTimeAfterCommit === NoWork ||
(childExpirationTimeAfterCommit !== NoWork &&
childExpirationTimeAfterCommit < updateExpirationTimeAfterCommit)
childExpirationTimeAfterCommit < updateExpirationTimeAfterCommit
? childExpirationTimeAfterCommit
: updateExpirationTimeAfterCommit;
if (earliestRemainingTimeAfterCommit === NoWork) {
Expand Down Expand Up @@ -776,10 +772,7 @@ function commitRoot(root: FiberRoot, finishedWork: Fiber): void {
// Only decrement the pending interaction count if we're done.
// If there's still work at the current priority,
// That indicates that we are waiting for suspense data.
if (
earliestRemainingTimeAfterCommit === NoWork ||
scheduledExpirationTime < earliestRemainingTimeAfterCommit
) {
if (scheduledExpirationTime < earliestRemainingTimeAfterCommit) {
pendingInteractionMap.delete(scheduledExpirationTime);

scheduledInteractions.forEach(interaction => {
Expand Down Expand Up @@ -839,18 +832,10 @@ function resetChildExpirationTime(
while (child !== null) {
const childUpdateExpirationTime = child.expirationTime;
const childChildExpirationTime = child.childExpirationTime;
if (
newChildExpirationTime === NoWork ||
(childUpdateExpirationTime !== NoWork &&
childUpdateExpirationTime < newChildExpirationTime)
) {
if (childUpdateExpirationTime < newChildExpirationTime) {
newChildExpirationTime = childUpdateExpirationTime;
}
if (
newChildExpirationTime === NoWork ||
(childChildExpirationTime !== NoWork &&
childChildExpirationTime < newChildExpirationTime)
) {
if (childChildExpirationTime < newChildExpirationTime) {
newChildExpirationTime = childChildExpirationTime;
}
if (shouldBubbleActualDurations) {
Expand All @@ -866,18 +851,10 @@ function resetChildExpirationTime(
while (child !== null) {
const childUpdateExpirationTime = child.expirationTime;
const childChildExpirationTime = child.childExpirationTime;
if (
newChildExpirationTime === NoWork ||
(childUpdateExpirationTime !== NoWork &&
childUpdateExpirationTime < newChildExpirationTime)
) {
if (childUpdateExpirationTime < newChildExpirationTime) {
newChildExpirationTime = childUpdateExpirationTime;
}
if (
newChildExpirationTime === NoWork ||
(childChildExpirationTime !== NoWork &&
childChildExpirationTime < newChildExpirationTime)
) {
if (childChildExpirationTime < newChildExpirationTime) {
newChildExpirationTime = childChildExpirationTime;
}
child = child.sibling;
Expand Down Expand Up @@ -1545,7 +1522,10 @@ function computeExpirationForFiber(currentTime: ExpirationTime, fiber: Fiber) {
// This is an interactive update. Keep track of the lowest pending
// interactive expiration time. This allows us to synchronously flush
// all interactive updates when needed.
if (expirationTime > lowestPriorityPendingInteractiveExpirationTime) {
if (
lowestPriorityPendingInteractiveExpirationTime === NoWork ||
expirationTime > lowestPriorityPendingInteractiveExpirationTime
) {
lowestPriorityPendingInteractiveExpirationTime = expirationTime;
}
}
Expand Down Expand Up @@ -1642,18 +1622,11 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
}

// Update the source fiber's expiration time
if (
fiber.expirationTime === NoWork ||
fiber.expirationTime > expirationTime
) {
if (fiber.expirationTime > expirationTime) {
fiber.expirationTime = expirationTime;
}
let alternate = fiber.alternate;
if (
alternate !== null &&
(alternate.expirationTime === NoWork ||
alternate.expirationTime > expirationTime)
) {
if (alternate !== null && alternate.expirationTime > expirationTime) {
alternate.expirationTime = expirationTime;
}
// Walk the parent path to the root and update the child expiration time.
Expand All @@ -1664,22 +1637,17 @@ function scheduleWorkToRoot(fiber: Fiber, expirationTime): FiberRoot | null {
} else {
while (node !== null) {
alternate = node.alternate;
if (
node.childExpirationTime === NoWork ||
node.childExpirationTime > expirationTime
) {
if (node.childExpirationTime > expirationTime) {
node.childExpirationTime = expirationTime;
if (
alternate !== null &&
(alternate.childExpirationTime === NoWork ||
alternate.childExpirationTime > expirationTime)
alternate.childExpirationTime > expirationTime
) {
alternate.childExpirationTime = expirationTime;
}
} else if (
alternate !== null &&
(alternate.childExpirationTime === NoWork ||
alternate.childExpirationTime > expirationTime)
alternate.childExpirationTime > expirationTime
) {
alternate.childExpirationTime = expirationTime;
}
Expand Down Expand Up @@ -2028,10 +1996,7 @@ function addRootToSchedule(root: FiberRoot, expirationTime: ExpirationTime) {
} else {
// This root is already scheduled, but its priority may have increased.
const remainingExpirationTime = root.expirationTime;
if (
remainingExpirationTime === NoWork ||
expirationTime < remainingExpirationTime
) {
if (expirationTime < remainingExpirationTime) {
// Update the priority.
root.expirationTime = expirationTime;
}
Expand Down Expand Up @@ -2080,10 +2045,7 @@ function findHighestPriorityRoot() {
}
root = previousScheduledRoot.nextScheduledRoot;
} else {
if (
highestPriorityWork === NoWork ||
remainingExpirationTime < highestPriorityWork
) {
if (remainingExpirationTime < highestPriorityWork) {
// Update the priority, if it's higher
highestPriorityWork = remainingExpirationTime;
highestPriorityRoot = root;
Expand Down Expand Up @@ -2150,8 +2112,7 @@ function performWork(minExpirationTime: ExpirationTime, dl: Deadline | null) {
while (
nextFlushedRoot !== null &&
nextFlushedExpirationTime !== NoWork &&
(minExpirationTime === NoWork ||
minExpirationTime >= nextFlushedExpirationTime) &&
minExpirationTime >= nextFlushedExpirationTime &&
(!deadlineDidExpire || currentRendererTime >= nextFlushedExpirationTime)
) {
performWorkOnRoot(
Expand All @@ -2167,8 +2128,7 @@ function performWork(minExpirationTime: ExpirationTime, dl: Deadline | null) {
while (
nextFlushedRoot !== null &&
nextFlushedExpirationTime !== NoWork &&
(minExpirationTime === NoWork ||
minExpirationTime >= nextFlushedExpirationTime)
minExpirationTime >= nextFlushedExpirationTime
) {
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, true);
findHighestPriorityRoot();
Expand Down
10 changes: 2 additions & 8 deletions packages/react-reconciler/src/ReactUpdateQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,7 @@ export function processUpdateQueue<State>(
}
// Since this update will remain in the list, update the remaining
// expiration time.
if (
newExpirationTime === NoWork ||
newExpirationTime > updateExpirationTime
) {
if (newExpirationTime > updateExpirationTime) {
newExpirationTime = updateExpirationTime;
}
} else {
Expand Down Expand Up @@ -490,10 +487,7 @@ export function processUpdateQueue<State>(
}
// Since this update will remain in the list, update the remaining
// expiration time.
if (
newExpirationTime === NoWork ||
newExpirationTime > updateExpirationTime
) {
if (newExpirationTime > updateExpirationTime) {
newExpirationTime = updateExpirationTime;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ exports[`ReactDebugFiberPerf measures deprioritized work 1`] = `
⚛ (Committing Host Effects: 1 Total)
⚛ (Calling Lifecycle Methods: 0 Total)

⚛ (Waiting for async callback... will force flush in 10737418210 ms)
⚛ (Waiting for async callback... will force flush in 10737418200 ms)

// Flush the child
⚛ (React Tree Reconciliation: Completed Root)
Expand Down