dillon1000/react
Commit
Browse files Detect and prevent render starvation, per lane (#18864)
* Detect and prevent render starvation, per lane If an update is CPU-bound for longer than expected according to its priority, we assume it's being starved by other work on the main thread. To detect this, we keep track of the elapsed time using a fixed-size array where each slot corresponds to a lane. What we actually store is the event time when the lane first became CPU-bound. Then, when receiving a new update or yielding to the main thread, we check how long each lane has been pending. If the time exceeds a threshold constant corresponding to its priority, we mark it as expired to force it to synchronously finish. We don't want to mistake time elapsed while an update is IO-bound (waiting for data to resolve) for time when it is CPU-bound. So when a lane suspends, we clear its associated event time from the array. When it receives a signal to try again, either a ping or an update, we assign a new event time to restart the clock. * Store as expiration time, not start time I originally stored the start time because I thought I could use this in the future to also measure Suspense timeouts. (Event times are currently stored on each update object for this purpose.) But that won't work because in the case of expiration times, we reset the clock whenever the update becomes IO-bound. So to replace the per-update field, I'm going to have to track those on the room separately from expiration times.
Changed paths16 files
First-parent comparisonpackages/react-reconciler/src/ReactFiberBeginWork.new.js ModifiedM packages/react-reconciler/src/ReactFiberClassComponent.new.js ModifiedM packages/react-reconciler/src/ReactFiberHooks.new.js ModifiedM packages/react-reconciler/src/ReactFiberHotReloading.new.js ModifiedM packages/react-reconciler/src/ReactFiberLane.js ModifiedM packages/react-reconciler/src/ReactFiberNewContext.new.js ModifiedM packages/react-reconciler/src/ReactFiberReconciler.new.js ModifiedM packages/react-reconciler/src/ReactFiberRoot.new.js ModifiedM packages/react-reconciler/src/ReactFiberRoot.old.js ModifiedM packages/react-reconciler/src/ReactFiberThrow.new.js ModifiedM packages/react-reconciler/src/ReactFiberWorkLoop.new.js ModifiedM packages/react-reconciler/src/ReactFiberWorkLoop.old.js ModifiedM packages/react-reconciler/src/ReactInternalTypes.js ModifiedM packages/react-reconciler/src/__tests__/ReactExpiration-test.js ModifiedM packages/react-reconciler/src/__tests__/ReactIncrementalUpdates-test.js ModifiedM packages/react/src/__tests__/ReactProfiler-test.internal.js ModifiedPatch
Files changed
Rendering syntax-highlighted changes…