@samitouri / QOS-React / commits / 4b8e1641b7

Fork performWork instead of using boolean flag (#15169)

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.

Sebastian Markbåge committed Mar 21, 2019 at 13:20 UTC 4b8e1641b77d0a5443403b8a2a8fa141c220c1a7
1 file changed +44 -27
packages/react-reconciler/src/ReactFiberScheduler.old.js
+44 -27
@@ -2234,23 +2234,18 @@ function performAsyncWork(didTimeout) {
2234 } while (root !== firstScheduledRoot);
2235 }
2236 }
2237 - let isYieldy = true;
2238 - if (disableYielding) {
2239 - isYieldy = false;
2240 - }
2241 - performWork(NoWork, isYieldy);
2242 -}
2243 -
2244 -function performSyncWork() {
2245 - performWork(Sync, false);
2246 -}
2237
2248 -function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
2238 // Keep working on roots until there's no more work, or until there's a higher
2239 // priority event.
2240 findHighestPriorityRoot();
2241
2253 - if (isYieldy) {
2242 + if (disableYielding) {
2243 + // Just do it all
2244 + while (nextFlushedRoot !== null && nextFlushedExpirationTime !== NoWork) {
2245 + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
2246 + findHighestPriorityRoot();
2247 + }
2248 + } else {
2249 recomputeCurrentRendererTime();
2250 currentSchedulerTime = currentRendererTime;
2251
@@ -2263,7 +2258,6 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
2258 while (
2259 nextFlushedRoot !== null &&
2260 nextFlushedExpirationTime !== NoWork &&
2266 - minExpirationTime <= nextFlushedExpirationTime &&
2261 !(shouldYield() && currentRendererTime > nextFlushedExpirationTime)
2262 ) {
2263 performWorkOnRoot(
@@ -2275,25 +2269,48 @@ function performWork(minExpirationTime: ExpirationTime, isYieldy: boolean) {
2269 recomputeCurrentRendererTime();
2270 currentSchedulerTime = currentRendererTime;
2271 }
2278 - } else {
2279 - while (
2280 - nextFlushedRoot !== null &&
2281 - nextFlushedExpirationTime !== NoWork &&
2282 - minExpirationTime <= nextFlushedExpirationTime
2283 - ) {
2284 - performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
2285 - findHighestPriorityRoot();
2286 - }
2272 }
2273
2274 // We're done flushing work. Either we ran out of time in this callback,
2275 // or there's no more work left with sufficient priority.
2276
2277 // If we're inside a callback, set this to false since we just completed it.
2293 - if (isYieldy) {
2294 - callbackExpirationTime = NoWork;
2295 - callbackID = null;
2278 + callbackExpirationTime = NoWork;
2279 + callbackID = null;
2280 +
2281 + // If there's work left over, schedule a new callback.
2282 + if (nextFlushedExpirationTime !== NoWork) {
2283 + scheduleCallbackWithExpirationTime(
2284 + ((nextFlushedRoot: any): FiberRoot),
2285 + nextFlushedExpirationTime,
2286 + );
2287 + }
2288 +
2289 + // Clean-up.
2290 + finishRendering();
2291 +}
2292 +
2293 +function performSyncWork() {
2294 + performWork(Sync);
2295 +}
2296 +
2297 +function performWork(minExpirationTime: ExpirationTime) {
2298 + // Keep working on roots until there's no more work, or until there's a higher
2299 + // priority event.
2300 + findHighestPriorityRoot();
2301 +
2302 + while (
2303 + nextFlushedRoot !== null &&
2304 + nextFlushedExpirationTime !== NoWork &&
2305 + minExpirationTime <= nextFlushedExpirationTime
2306 + ) {
2307 + performWorkOnRoot(nextFlushedRoot, nextFlushedExpirationTime, false);
2308 + findHighestPriorityRoot();
2309 }
2310 +
2311 + // We're done flushing work. Either we ran out of time in this callback,
2312 + // or there's no more work left with sufficient priority.
2313 +
2314 // If there's work left over, schedule a new callback.
2315 if (nextFlushedExpirationTime !== NoWork) {
2316 scheduleCallbackWithExpirationTime(
@@ -2547,7 +2564,7 @@ function interactiveUpdates<A, B, C, R>(
2564 lowestPriorityPendingInteractiveExpirationTime !== NoWork
2565 ) {
2566 // Synchronously flush pending interactive updates.
2550 - performWork(lowestPriorityPendingInteractiveExpirationTime, false);
2567 + performWork(lowestPriorityPendingInteractiveExpirationTime);
2568 lowestPriorityPendingInteractiveExpirationTime = NoWork;
2569 }
2570 const previousIsBatchingInteractiveUpdates = isBatchingInteractiveUpdates;
@@ -2571,7 +2588,7 @@ function flushInteractiveUpdates() {
2588 lowestPriorityPendingInteractiveExpirationTime !== NoWork
2589 ) {
2590 // Synchronously flush pending interactive updates.
2574 - performWork(lowestPriorityPendingInteractiveExpirationTime, false);
2591 + performWork(lowestPriorityPendingInteractiveExpirationTime);
2592 lowestPriorityPendingInteractiveExpirationTime = NoWork;
2593 }
2594 }