@samitouri / QOS-React-2 / commits / 96ac799eac

Remove `callbackId` field from FiberRoot (#19458)

The old expiration times implementation used this field to infer when the priority of a task had changed at a more granular level than a Scheduler priority level. Now that we have the LanePriority type, which is React-specific, we no longer need the `callbackId` field.

Andrew Clark committed Jul 27, 2020 at 12:39 UTC 96ac799eace5d989de3b4f80e6414e94a08ff77a
5 files changed +29 -47
packages/react-reconciler/src/ReactFiberRoot.new.js
-1
@@ -38,7 +38,6 @@ function FiberRootNode(containerInfo, tag, hydrate) {
38 this.pendingContext = null;
39 this.hydrate = hydrate;
40 this.callbackNode = null;
41 - this.callbackId = NoLanes;
41 this.callbackPriority = NoLanePriority;
42 this.eventTimes = createLaneMap(NoLanes);
43 this.expirationTimes = createLaneMap(NoTimestamp);
packages/react-reconciler/src/ReactFiberRoot.old.js
-1
@@ -38,7 +38,6 @@ function FiberRootNode(containerInfo, tag, hydrate) {
38 this.pendingContext = null;
39 this.hydrate = hydrate;
40 this.callbackNode = null;
41 - this.callbackId = NoLanes;
41 this.callbackPriority = NoLanePriority;
42 this.eventTimes = createLaneMap(NoLanes);
43 this.expirationTimes = createLaneMap(NoTimestamp);
packages/react-reconciler/src/ReactFiberWorkLoop.new.js
+13 -20
@@ -677,10 +677,10 @@ function markUpdateLaneFromFiberToRoot(
677 }
678
679 // Use this function to schedule a task for a root. There's only one task per
680 -// root; if a task was already scheduled, we'll check to make sure the
681 -// expiration time of the existing task is the same as the expiration time of
682 -// the next level that the root has work on. This function is called on every
683 -// update, and right before exiting a task.
680 +// root; if a task was already scheduled, we'll check to make sure the priority
681 +// of the existing task is the same as the priority of the next level that the
682 +// root has work on. This function is called on every update, and right before
683 +// exiting a task.
684 function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
685 const existingCallbackNode = root.callbackNode;
686
@@ -689,37 +689,32 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
689 markStarvedLanesAsExpired(root, currentTime);
690
691 // Determine the next lanes to work on, and their priority.
692 - const newCallbackId = getNextLanes(
692 + const nextLanes = getNextLanes(
693 root,
694 root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
695 );
696 // This returns the priority level computed during the `getNextLanes` call.
697 const newCallbackPriority = returnNextLanesPriority();
698
699 - if (newCallbackId === NoLanes) {
699 + if (nextLanes === NoLanes) {
700 // Special case: There's nothing to work on.
701 if (existingCallbackNode !== null) {
702 cancelCallback(existingCallbackNode);
703 root.callbackNode = null;
704 root.callbackPriority = NoLanePriority;
705 - root.callbackId = NoLanes;
705 }
706 return;
707 }
708
709 // Check if there's an existing task. We may be able to reuse it.
711 - const existingCallbackId = root.callbackId;
712 - const existingCallbackPriority = root.callbackPriority;
713 - if (existingCallbackId !== NoLanes) {
714 - if (newCallbackId === existingCallbackId) {
715 - // This task is already scheduled. Let's check its priority.
716 - if (existingCallbackPriority === newCallbackPriority) {
717 - // The priority hasn't changed. Exit.
718 - return;
719 - }
720 - // The task ID is the same but the priority changed. Cancel the existing
721 - // callback. We'll schedule a new one below.
710 + if (existingCallbackNode !== null) {
711 + const existingCallbackPriority = root.callbackPriority;
712 + if (existingCallbackPriority === newCallbackPriority) {
713 + // The priority hasn't changed. We can reuse the existing task. Exit.
714 + return;
715 }
716 + // The priority changed. Cancel the existing callback. We'll schedule a new
717 + // one below.
718 cancelCallback(existingCallbackNode);
719 }
720
@@ -741,7 +736,6 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
736 );
737 }
738
744 - root.callbackId = newCallbackId;
739 root.callbackPriority = newCallbackPriority;
740 root.callbackNode = newCallbackNode;
741 }
@@ -2041,7 +2035,6 @@ function commitRootImpl(root, renderPriorityLevel) {
2035 // commitRoot never returns a continuation; it always finishes synchronously.
2036 // So we can clear these now to allow a new callback to be scheduled.
2037 root.callbackNode = null;
2044 - root.callbackId = NoLanes;
2038
2039 // Update the first and last pending times on this root. The new first
2040 // pending time is whatever is left on the root fiber.
packages/react-reconciler/src/ReactFiberWorkLoop.old.js
+13 -20
@@ -670,10 +670,10 @@ function markUpdateLaneFromFiberToRoot(
670 }
671
672 // Use this function to schedule a task for a root. There's only one task per
673 -// root; if a task was already scheduled, we'll check to make sure the
674 -// expiration time of the existing task is the same as the expiration time of
675 -// the next level that the root has work on. This function is called on every
676 -// update, and right before exiting a task.
673 +// root; if a task was already scheduled, we'll check to make sure the priority
674 +// of the existing task is the same as the priority of the next level that the
675 +// root has work on. This function is called on every update, and right before
676 +// exiting a task.
677 function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
678 const existingCallbackNode = root.callbackNode;
679
@@ -682,37 +682,32 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
682 markStarvedLanesAsExpired(root, currentTime);
683
684 // Determine the next lanes to work on, and their priority.
685 - const newCallbackId = getNextLanes(
685 + const nextLanes = getNextLanes(
686 root,
687 root === workInProgressRoot ? workInProgressRootRenderLanes : NoLanes,
688 );
689 // This returns the priority level computed during the `getNextLanes` call.
690 const newCallbackPriority = returnNextLanesPriority();
691
692 - if (newCallbackId === NoLanes) {
692 + if (nextLanes === NoLanes) {
693 // Special case: There's nothing to work on.
694 if (existingCallbackNode !== null) {
695 cancelCallback(existingCallbackNode);
696 root.callbackNode = null;
697 root.callbackPriority = NoLanePriority;
698 - root.callbackId = NoLanes;
698 }
699 return;
700 }
701
702 // Check if there's an existing task. We may be able to reuse it.
704 - const existingCallbackId = root.callbackId;
705 - const existingCallbackPriority = root.callbackPriority;
706 - if (existingCallbackId !== NoLanes) {
707 - if (newCallbackId === existingCallbackId) {
708 - // This task is already scheduled. Let's check its priority.
709 - if (existingCallbackPriority === newCallbackPriority) {
710 - // The priority hasn't changed. Exit.
711 - return;
712 - }
713 - // The task ID is the same but the priority changed. Cancel the existing
714 - // callback. We'll schedule a new one below.
703 + if (existingCallbackNode !== null) {
704 + const existingCallbackPriority = root.callbackPriority;
705 + if (existingCallbackPriority === newCallbackPriority) {
706 + // The priority hasn't changed. We can reuse the existing task. Exit.
707 + return;
708 }
709 + // The priority changed. Cancel the existing callback. We'll schedule a new
710 + // one below.
711 cancelCallback(existingCallbackNode);
712 }
713
@@ -734,7 +729,6 @@ function ensureRootIsScheduled(root: FiberRoot, currentTime: number) {
729 );
730 }
731
737 - root.callbackId = newCallbackId;
732 root.callbackPriority = newCallbackPriority;
733 root.callbackNode = newCallbackNode;
734 }
@@ -1959,7 +1953,6 @@ function commitRootImpl(root, renderPriorityLevel) {
1953 // commitRoot never returns a continuation; it always finishes synchronously.
1954 // So we can clear these now to allow a new callback to be scheduled.
1955 root.callbackNode = null;
1962 - root.callbackId = NoLanes;
1956
1957 // Update the first and last pending times on this root. The new first
1958 // pending time is whatever is left on the root fiber.
packages/react-reconciler/src/ReactInternalTypes.js
+3 -5
@@ -205,17 +205,15 @@ type BaseFiberRootProperties = {|
205 pendingContext: Object | null,
206 // Determines if we should attempt to hydrate on the initial mount
207 +hydrate: boolean,
208 - // Node returned by Scheduler.scheduleCallback
209 - callbackNode: *,
208
209 // Used by useMutableSource hook to avoid tearing during hydration.
210 mutableSourceEagerHydrationData?: Array<
211 MutableSource<any> | MutableSourceVersion,
212 > | null,
213
216 - // Represents the next task that the root should work on, or the current one
217 - // if it's already working.
218 - callbackId: Lanes,
214 + // Node returned by Scheduler.scheduleCallback. Represents the next rendering
215 + // task that the root will work on.
216 + callbackNode: *,
217 callbackPriority: LanePriority,
218 eventTimes: LaneMap<number>,
219 expirationTimes: LaneMap<number>,