Skip to content

Commit

Permalink
Fork performWork instead of using boolean flag (#15169)
Browse files Browse the repository at this point in the history
I inline it into performAsyncWork instead.

Code that was only relevant to the async callback had leaked into the
performWork call which is an indication that this was a bad abstraction
and therefore the wrong place to DRY.

By inlining I also discovered that minExpirationTime is actually irrelevant
in the yieldy case so we can clean that up.
  • Loading branch information
sebmarkbage authored Mar 21, 2019
1 parent 56035da commit 4b8e164
Showing 1 changed file with 44 additions and 27 deletions.
71 changes: 44 additions & 27 deletions packages/react-reconciler/src/ReactFiberScheduler.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -2234,23 +2234,18 @@ function performAsyncWork(didTimeout) {
} while (root !== firstScheduledRoot);
}
}
let isYieldy = true;
if (disableYielding) {
isYieldy = false;
}
performWork(NoWork, isYieldy);
}

function performSyncWork() {
performWork(Sync, false);
}

function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
// Keep working on roots until there's no more work, or until there's a higher
// priority event.
findHighestPriorityRoot();

if (isYieldy) {
if (disableYielding) {
// Just do it all
while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork) {
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
findHighestPriorityRoot();
}
} else {
recomputeCurrentRendererTime();
currentSchedulerTime = currentRendererTime;

Expand All @@ -2263,7 +2258,6 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
while (
nextFlushedRoot !== null &&
nextFlushedExpirationTime !== NoWork &&
minExpirationTime <= nextFlushedExpirationTime &&
!(shouldYield() && currentRendererTime > nextFlushedExpirationTime)
) {
performWorkOnRoot(
Expand All @@ -2275,25 +2269,48 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
recomputeCurrentRendererTime();
currentSchedulerTime = currentRendererTime;
}
} else {
while (
nextFlushedRoot !== null &&
nextFlushedExpirationTime !== NoWork &&
minExpirationTime <= nextFlushedExpirationTime
) {
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
findHighestPriorityRoot();
}
}

// We're done flushing work. Either we ran out of time in this callback,
// or there's no more work left with sufficient priority.

// If we're inside a callback, set this to false since we just completed it.
if (isYieldy) {
callbackExpirationTime = NoWork;
callbackID = null;
callbackExpirationTime = NoWork;
callbackID = null;

// If there's work left over, schedule a new callback.
if (nextFlushedExpirationTime !== NoWork) {
scheduleCallbackWithExpirationTime(
((nextFlushedRoot: any): FiberRoot),
nextFlushedExpirationTime,
);
}

// Clean-up.
finishRendering();
}

function performSyncWork() {
performWork(Sync);
}

function performWork(minExpirationTime: ExpirationTime) {
// Keep working on roots until there's no more work, or until there's a higher
// priority event.
findHighestPriorityRoot();

while (
nextFlushedRoot !== null &&
nextFlushedExpirationTime !== NoWork &&
minExpirationTime <= nextFlushedExpirationTime
) {
performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
findHighestPriorityRoot();
}

// We're done flushing work. Either we ran out of time in this callback,
// or there's no more work left with sufficient priority.

// If there's work left over, schedule a new callback.
if (nextFlushedExpirationTime !== NoWork) {
scheduleCallbackWithExpirationTime(
Expand Down Expand Up @@ -2547,7 +2564,7 @@ function interactiveUpdates<A, B, C, R>(
lowestPriorityPendingInteractiveExpirationTime !== NoWork
) {
// Synchronously flush pending interactive updates.
performWork(lowestPriorityPendingInteractiveExpirationTime, false);
performWork(lowestPriorityPendingInteractiveExpirationTime);
lowestPriorityPendingInteractiveExpirationTime = NoWork;
}
const previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates;
Expand All @@ -2571,7 +2588,7 @@ function flushInteractiveUpdates() {
lowestPriorityPendingInteractiveExpirationTime !== NoWork
) {
// Synchronously flush pending interactive updates.
performWork(lowestPriorityPendingInteractiveExpirationTime, false);
performWork(lowestPriorityPendingInteractiveExpirationTime);
lowestPriorityPendingInteractiveExpirationTime = NoWork;
}
}
Expand Down

0 comments on commit 4b8e164

Please sign in to comment.