@samitouri / QOS-React-2 / commits / 58742c21b8

Delete unused `eventTimes` Fiber field (#26599)

Andrew Clark committed Apr 11, 2023 at 08:23 UTC 58742c21b8c3237e8b66c7df4e200504846a01ae
11 files changed +37 -133
packages/react-reconciler/src/ReactFiberBeginWork.js
+1 -9
@@ -142,7 +142,6 @@ import {
142 OffscreenLane,
143 DefaultHydrationLane,
144 SomeRetryLane,
145 - NoTimestamp,
145 includesSomeLane,
146 laneToLanes,
147 removeLanes,
@@ -2876,15 +2875,8 @@ function updateDehydratedSuspenseComponent(
2875 // is one of the very rare times where we mutate the current tree
2876 // during the render phase.
2877 suspenseState.retryLane = attemptHydrationAtLane;
2879 - // TODO: Ideally this would inherit the event time of the current render
2880 - const eventTime = NoTimestamp;
2878 enqueueConcurrentRenderForLane(current, attemptHydrationAtLane);
2882 - scheduleUpdateOnFiber(
2883 - root,
2884 - current,
2885 - attemptHydrationAtLane,
2886 - eventTime,
2887 - );
2879 + scheduleUpdateOnFiber(root, current, attemptHydrationAtLane);
2880
2881 // Throw a special object that signals to the work loop that it should
2882 // interrupt the current render.
packages/react-reconciler/src/ReactFiberClassComponent.js
+4 -11
@@ -64,11 +64,7 @@ import {
64 emptyContextObject,
65 } from './ReactFiberContext';
66 import {readContext, checkIfContextChanged} from './ReactFiberNewContext';
67 -import {
68 - requestEventTime,
69 - requestUpdateLane,
70 - scheduleUpdateOnFiber,
71 -} from './ReactFiberWorkLoop';
67 +import {requestUpdateLane, scheduleUpdateOnFiber} from './ReactFiberWorkLoop';
68 import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing';
69 import {
70 markForceUpdateScheduled,
@@ -213,8 +209,7 @@ const classComponentUpdater = {
209
210 const root = enqueueUpdate(fiber, update, lane);
211 if (root !== null) {
216 - const eventTime = requestEventTime();
217 - scheduleUpdateOnFiber(root, fiber, lane, eventTime);
212 + scheduleUpdateOnFiber(root, fiber, lane);
213 entangleTransitions(root, fiber, lane);
214 }
215
@@ -248,8 +243,7 @@ const classComponentUpdater = {
243
244 const root = enqueueUpdate(fiber, update, lane);
245 if (root !== null) {
251 - const eventTime = requestEventTime();
252 - scheduleUpdateOnFiber(root, fiber, lane, eventTime);
246 + scheduleUpdateOnFiber(root, fiber, lane);
247 entangleTransitions(root, fiber, lane);
248 }
249
@@ -283,8 +277,7 @@ const classComponentUpdater = {
277
278 const root = enqueueUpdate(fiber, update, lane);
279 if (root !== null) {
286 - const eventTime = requestEventTime();
287 - scheduleUpdateOnFiber(root, fiber, lane, eventTime);
280 + scheduleUpdateOnFiber(root, fiber, lane);
281 entangleTransitions(root, fiber, lane);
282 }
283
packages/react-reconciler/src/ReactFiberCommitWork.js
+3 -3
@@ -18,7 +18,7 @@ import type {
18 } from './ReactFiberConfig';
19 import type {Fiber, FiberRoot} from './ReactInternalTypes';
20 import type {Lanes} from './ReactFiberLane';
21 -import {NoTimestamp, SyncLane} from './ReactFiberLane';
21 +import {SyncLane} from './ReactFiberLane';
22 import type {SuspenseState, RetryQueue} from './ReactFiberSuspenseComponent';
23 import type {UpdateQueue} from './ReactFiberClassUpdateQueue';
24 import type {FunctionComponentUpdateQueue} from './ReactFiberHooks';
@@ -2415,7 +2415,7 @@ export function detachOffscreenInstance(instance: OffscreenInstance): void {
2415 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
2416 if (root !== null) {
2417 instance._pendingVisibility |= OffscreenDetached;
2418 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
2418 + scheduleUpdateOnFiber(root, fiber, SyncLane);
2419 }
2420 }
2421
@@ -2435,7 +2435,7 @@ export function attachOffscreenInstance(instance: OffscreenInstance): void {
2435 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
2436 if (root !== null) {
2437 instance._pendingVisibility &= ~OffscreenDetached;
2438 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
2438 + scheduleUpdateOnFiber(root, fiber, SyncLane);
2439 }
2440 }
2441
packages/react-reconciler/src/ReactFiberHooks.js
+4 -9
@@ -70,7 +70,6 @@ import {
70 isTransitionLane,
71 markRootEntangled,
72 markRootMutableRead,
73 - NoTimestamp,
73 } from './ReactFiberLane';
74 import {
75 ContinuousEventPriority,
@@ -101,7 +100,6 @@ import {
100 getWorkInProgressRootRenderLanes,
101 scheduleUpdateOnFiber,
102 requestUpdateLane,
104 - requestEventTime,
103 markSkippedUpdateLanes,
104 isInvalidExecutionContextForEventFunction,
105 } from './ReactFiberWorkLoop';
@@ -1837,7 +1835,7 @@ function checkIfSnapshotChanged<T>(inst: StoreInstance<T>): boolean {
1835 function forceStoreRerender(fiber: Fiber) {
1836 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
1837 if (root !== null) {
1840 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
1838 + scheduleUpdateOnFiber(root, fiber, SyncLane);
1839 }
1840 }
1841
@@ -2558,8 +2556,7 @@ function refreshCache<T>(fiber: Fiber, seedKey: ?() => T, seedValue: T): void {
2556 const refreshUpdate = createLegacyQueueUpdate(lane);
2557 const root = enqueueLegacyQueueUpdate(provider, refreshUpdate, lane);
2558 if (root !== null) {
2561 - const eventTime = requestEventTime();
2562 - scheduleUpdateOnFiber(root, provider, lane, eventTime);
2559 + scheduleUpdateOnFiber(root, provider, lane);
2560 entangleLegacyQueueTransitions(root, provider, lane);
2561 }
2562
@@ -2623,8 +2620,7 @@ function dispatchReducerAction<S, A>(
2620 } else {
2621 const root = enqueueConcurrentHookUpdate(fiber, queue, update, lane);
2622 if (root !== null) {
2626 - const eventTime = requestEventTime();
2627 - scheduleUpdateOnFiber(root, fiber, lane, eventTime);
2623 + scheduleUpdateOnFiber(root, fiber, lane);
2624 entangleTransitionUpdate(root, queue, lane);
2625 }
2626 }
@@ -2706,8 +2702,7 @@ function dispatchSetState<S, A>(
2702
2703 const root = enqueueConcurrentHookUpdate(fiber, queue, update, lane);
2704 if (root !== null) {
2709 - const eventTime = requestEventTime();
2710 - scheduleUpdateOnFiber(root, fiber, lane, eventTime);
2705 + scheduleUpdateOnFiber(root, fiber, lane);
2706 entangleTransitionUpdate(root, queue, lane);
2707 }
2708 }
packages/react-reconciler/src/ReactFiberHotReloading.js
+2 -2
@@ -23,7 +23,7 @@ import {
23 import {enqueueConcurrentRenderForLane} from './ReactFiberConcurrentUpdates';
24 import {updateContainer} from './ReactFiberReconciler';
25 import {emptyContextObject} from './ReactFiberContext';
26 -import {SyncLane, NoTimestamp} from './ReactFiberLane';
26 +import {SyncLane} from './ReactFiberLane';
27 import {
28 ClassComponent,
29 FunctionComponent,
@@ -328,7 +328,7 @@ function scheduleFibersWithFamiliesRecursively(
328 if (needsRemount || needsRender) {
329 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
330 if (root !== null) {
331 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
331 + scheduleUpdateOnFiber(root, fiber, SyncLane);
332 }
333 }
334 if (child !== null && !needsRemount) {
packages/react-reconciler/src/ReactFiberLane.js
+1 -32
@@ -319,25 +319,6 @@ export function getNextLanes(root: FiberRoot, wipLanes: Lanes): Lanes {
319 return nextLanes;
320 }
321
322 -export function getMostRecentEventTime(root: FiberRoot, lanes: Lanes): number {
323 - const eventTimes = root.eventTimes;
324 -
325 - let mostRecentEventTime = NoTimestamp;
326 - while (lanes > 0) {
327 - const index = pickArbitraryLaneIndex(lanes);
328 - const lane = 1 << index;
329 -
330 - const eventTime = eventTimes[index];
331 - if (eventTime > mostRecentEventTime) {
332 - mostRecentEventTime = eventTime;
333 - }
334 -
335 - lanes &= ~lane;
336 - }
337 -
338 - return mostRecentEventTime;
339 -}
340 -
322 function computeExpirationTime(lane: Lane, currentTime: number) {
323 switch (lane) {
324 case SyncHydrationLane:
@@ -599,11 +580,7 @@ export function createLaneMap<T>(initial: T): LaneMap<T> {
580 return laneMap;
581 }
582
602 -export function markRootUpdated(
603 - root: FiberRoot,
604 - updateLane: Lane,
605 - eventTime: number,
606 -) {
583 +export function markRootUpdated(root: FiberRoot, updateLane: Lane) {
584 root.pendingLanes |= updateLane;
585
586 // If there are any suspended transitions, it's possible this new update
@@ -622,12 +599,6 @@ export function markRootUpdated(
599 root.suspendedLanes = NoLanes;
600 root.pingedLanes = NoLanes;
601 }
625 -
626 - const eventTimes = root.eventTimes;
627 - const index = laneToIndex(updateLane);
628 - // We can always overwrite an existing timestamp because we prefer the most
629 - // recent event, and we assume time is monotonically increasing.
630 - eventTimes[index] = eventTime;
602 }
603
604 export function markRootSuspended(root: FiberRoot, suspendedLanes: Lanes) {
@@ -672,7 +643,6 @@ export function markRootFinished(root: FiberRoot, remainingLanes: Lanes) {
643 root.errorRecoveryDisabledLanes &= remainingLanes;
644
645 const entanglements = root.entanglements;
675 - const eventTimes = root.eventTimes;
646 const expirationTimes = root.expirationTimes;
647 const hiddenUpdates = root.hiddenUpdates;
648
@@ -683,7 +653,6 @@ export function markRootFinished(root: FiberRoot, remainingLanes: Lanes) {
653 const lane = 1 << index;
654
655 entanglements[index] = NoLanes;
686 - eventTimes[index] = NoTimestamp;
656 expirationTimes[index] = NoTimestamp;
657
658 const hiddenUpdatesForLane = hiddenUpdates[index];
packages/react-reconciler/src/ReactFiberReconciler.js
+12 -19
@@ -56,7 +56,6 @@ import {
56 onScheduleRoot,
57 } from './ReactFiberDevToolsHook';
58 import {
59 - requestEventTime,
59 requestUpdateLane,
60 scheduleUpdateOnFiber,
61 scheduleInitialHydrationOnRoot,
@@ -84,7 +83,6 @@ import {StrictLegacyMode} from './ReactTypeOfMode';
83 import {
84 SyncLane,
85 SelectiveHydrationLane,
87 - NoTimestamp,
86 getHighestPriorityPendingLanes,
87 higherPriorityLane,
88 } from './ReactFiberLane';
@@ -311,9 +309,8 @@ export function createHydrationContainer(
309 const update = createUpdate(lane);
310 update.callback =
311 callback !== undefined && callback !== null ? callback : null;
314 - const eventTime = requestEventTime();
312 enqueueUpdate(current, update, lane);
316 - scheduleInitialHydrationOnRoot(root, lane, eventTime);
313 + scheduleInitialHydrationOnRoot(root, lane);
314
315 return root;
316 }
@@ -379,8 +376,7 @@ export function updateContainer(
376
377 const root = enqueueUpdate(current, update, lane);
378 if (root !== null) {
382 - const eventTime = requestEventTime();
383 - scheduleUpdateOnFiber(root, current, lane, eventTime);
379 + scheduleUpdateOnFiber(root, current, lane);
380 entangleTransitions(root, current, lane);
381 }
382
@@ -427,8 +423,7 @@ export function attemptSynchronousHydration(fiber: Fiber): void {
423 flushSync(() => {
424 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
425 if (root !== null) {
430 - const eventTime = requestEventTime();
431 - scheduleUpdateOnFiber(root, fiber, SyncLane, eventTime);
426 + scheduleUpdateOnFiber(root, fiber, SyncLane);
427 }
428 });
429 // If we're still blocked after this, we need to increase
@@ -471,8 +466,7 @@ export function attemptContinuousHydration(fiber: Fiber): void {
466 const lane = SelectiveHydrationLane;
467 const root = enqueueConcurrentRenderForLane(fiber, lane);
468 if (root !== null) {
474 - const eventTime = requestEventTime();
475 - scheduleUpdateOnFiber(root, fiber, lane, eventTime);
469 + scheduleUpdateOnFiber(root, fiber, lane);
470 }
471 markRetryLaneIfNotHydrated(fiber, lane);
472 }
@@ -486,8 +480,7 @@ export function attemptHydrationAtCurrentPriority(fiber: Fiber): void {
480 const lane = requestUpdateLane(fiber);
481 const root = enqueueConcurrentRenderForLane(fiber, lane);
482 if (root !== null) {
489 - const eventTime = requestEventTime();
490 - scheduleUpdateOnFiber(root, fiber, lane, eventTime);
483 + scheduleUpdateOnFiber(root, fiber, lane);
484 }
485 markRetryLaneIfNotHydrated(fiber, lane);
486 }
@@ -666,7 +659,7 @@ if (__DEV__) {
659
660 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
661 if (root !== null) {
669 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
662 + scheduleUpdateOnFiber(root, fiber, SyncLane);
663 }
664 }
665 };
@@ -690,7 +683,7 @@ if (__DEV__) {
683
684 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
685 if (root !== null) {
693 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
686 + scheduleUpdateOnFiber(root, fiber, SyncLane);
687 }
688 }
689 };
@@ -715,7 +708,7 @@ if (__DEV__) {
708
709 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
710 if (root !== null) {
718 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
711 + scheduleUpdateOnFiber(root, fiber, SyncLane);
712 }
713 }
714 };
@@ -728,7 +721,7 @@ if (__DEV__) {
721 }
722 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
723 if (root !== null) {
731 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
724 + scheduleUpdateOnFiber(root, fiber, SyncLane);
725 }
726 };
727 overridePropsDeletePath = (fiber: Fiber, path: Array<string | number>) => {
@@ -738,7 +731,7 @@ if (__DEV__) {
731 }
732 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
733 if (root !== null) {
741 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
734 + scheduleUpdateOnFiber(root, fiber, SyncLane);
735 }
736 };
737 overridePropsRenamePath = (
@@ -752,14 +745,14 @@ if (__DEV__) {
745 }
746 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
747 if (root !== null) {
755 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
748 + scheduleUpdateOnFiber(root, fiber, SyncLane);
749 }
750 };
751
752 scheduleUpdate = (fiber: Fiber) => {
753 const root = enqueueConcurrentRenderForLane(fiber, SyncLane);
754 if (root !== null) {
762 - scheduleUpdateOnFiber(root, fiber, SyncLane, NoTimestamp);
755 + scheduleUpdateOnFiber(root, fiber, SyncLane);
756 }
757 };
758
packages/react-reconciler/src/ReactFiberRoot.js
-1
@@ -66,7 +66,6 @@ function FiberRootNode(
66 this.next = null;
67 this.callbackNode = null;
68 this.callbackPriority = NoLane;
69 - this.eventTimes = createLaneMap(NoLanes);
69 this.expirationTimes = createLaneMap(NoTimestamp);
70
71 this.pendingLanes = NoLanes;
packages/react-reconciler/src/ReactFiberWorkLoop.js
+6 -37
@@ -130,7 +130,6 @@ import {
130 NoLanes,
131 NoLane,
132 SyncLane,
133 - NoTimestamp,
133 claimNextTransitionLane,
134 claimNextRetryLane,
135 includesSyncLane,
@@ -584,10 +583,6 @@ const NESTED_PASSIVE_UPDATE_LIMIT = 50;
583 let nestedPassiveUpdateCount: number = 0;
584 let rootWithPassiveNestedUpdates: FiberRoot | null = null;
585
587 -// If two updates are scheduled within the same event, we should treat their
588 -// event times as simultaneous, even if the actual clock time has advanced
589 -// between the first and second call.
590 -let currentEventTime: number = NoTimestamp;
586 let currentEventTransitionLane: Lanes = NoLanes;
587
588 let isRunningInsertionEffect = false;
@@ -604,21 +599,6 @@ export function isWorkLoopSuspendedOnData(): boolean {
599 return workInProgressSuspendedReason === SuspendedOnData;
600 }
601
607 -export function requestEventTime(): number {
608 - if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
609 - // We're inside React, so it's fine to read the actual time.
610 - return now();
611 - }
612 - // We're not inside React, so we may be in the middle of a browser event.
613 - if (currentEventTime !== NoTimestamp) {
614 - // Use the same start time for all updates until we enter React again.
615 - return currentEventTime;
616 - }
617 - // This is the first update since React yielded. Compute a new start time.
618 - currentEventTime = now();
619 - return currentEventTime;
620 -}
621 -
602 export function getCurrentTime(): number {
603 return now();
604 }
@@ -707,7 +687,6 @@ export function scheduleUpdateOnFiber(
687 root: FiberRoot,
688 fiber: Fiber,
689 lane: Lane,
710 - eventTime: number,
690 ) {
691 if (__DEV__) {
692 if (isRunningInsertionEffect) {
@@ -737,7 +716,7 @@ export function scheduleUpdateOnFiber(
716 }
717
718 // Mark that the root has a pending update.
740 - markRootUpdated(root, lane, eventTime);
719 + markRootUpdated(root, lane);
720
721 if (
722 (executionContext & RenderContext) !== NoLanes &&
@@ -838,11 +817,7 @@ export function scheduleUpdateOnFiber(
817 }
818 }
819
841 -export function scheduleInitialHydrationOnRoot(
842 - root: FiberRoot,
843 - lane: Lane,
844 - eventTime: number,
845 -) {
820 +export function scheduleInitialHydrationOnRoot(root: FiberRoot, lane: Lane) {
821 // This is a special fork of scheduleUpdateOnFiber that is only used to
822 // schedule the initial hydration of a root that has just been created. Most
823 // of the stuff in scheduleUpdateOnFiber can be skipped.
@@ -854,7 +829,7 @@ export function scheduleInitialHydrationOnRoot(
829 // match what was rendered on the server.
830 const current = root.current;
831 current.lanes = lane;
857 - markRootUpdated(root, lane, eventTime);
832 + markRootUpdated(root, lane);
833 ensureRootIsScheduled(root);
834 }
835
@@ -874,9 +849,6 @@ export function performConcurrentWorkOnRoot(
849 resetNestedUpdateFlag();
850 }
851
877 - // Since we know we're in a React event, we can clear the current
878 - // event time. The next update will compute a new event time.
879 - currentEventTime = NoTimestamp;
852 currentEventTransitionLane = NoLanes;
853
854 if ((executionContext & (RenderContext | CommitContext)) !== NoContext) {
@@ -3313,9 +3285,8 @@ function captureCommitPhaseErrorOnRoot(
3285 const errorInfo = createCapturedValueAtFiber(error, sourceFiber);
3286 const update = createRootErrorUpdate(rootFiber, errorInfo, (SyncLane: Lane));
3287 const root = enqueueUpdate(rootFiber, update, (SyncLane: Lane));
3316 - const eventTime = requestEventTime();
3288 if (root !== null) {
3318 - markRootUpdated(root, SyncLane, eventTime);
3289 + markRootUpdated(root, SyncLane);
3290 ensureRootIsScheduled(root);
3291 }
3292 }
@@ -3356,9 +3327,8 @@ export function captureCommitPhaseError(
3327 (SyncLane: Lane),
3328 );
3329 const root = enqueueUpdate(fiber, update, (SyncLane: Lane));
3359 - const eventTime = requestEventTime();
3330 if (root !== null) {
3361 - markRootUpdated(root, SyncLane, eventTime);
3331 + markRootUpdated(root, SyncLane);
3332 ensureRootIsScheduled(root);
3333 }
3334 return;
@@ -3493,10 +3463,9 @@ function retryTimedOutBoundary(boundaryFiber: Fiber, retryLane: Lane) {
3463 retryLane = requestRetryLane(boundaryFiber);
3464 }
3465 // TODO: Special case idle priority?
3496 - const eventTime = requestEventTime();
3466 const root = enqueueConcurrentRenderForLane(boundaryFiber, retryLane);
3467 if (root !== null) {
3499 - markRootUpdated(root, retryLane, eventTime);
3468 + markRootUpdated(root, retryLane);
3469 ensureRootIsScheduled(root);
3470 }
3471 }
packages/react-reconciler/src/ReactInternalTypes.js
-1
@@ -248,7 +248,6 @@ type BaseFiberRootProperties = {
248 // task that the root will work on.
249 callbackNode: any,
250 callbackPriority: Lane,
251 - eventTimes: LaneMap<number>,
251 expirationTimes: LaneMap<number>,
252 hiddenUpdates: LaneMap<Array<ConcurrentUpdate> | null>,
253
packages/react/src/__tests__/ReactProfiler-test.internal.js
+4 -9
@@ -268,14 +268,13 @@ describe(`onRender`, () => {
268 </div>,
269 );
270
271 + // Restore original mock
272 + jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'));
273 +
274 // TODO: unstable_now is called by more places than just the profiler.
275 // Rewrite this test so it's less fragile.
276 if (gate(flags => flags.enableDeferRootSchedulingToMicrotask)) {
274 - assertLog([
275 - 'read current time',
276 - 'read current time',
277 - 'read current time',
278 - ]);
277 + assertLog(['read current time', 'read current time']);
278 } else {
279 assertLog([
280 'read current time',
@@ -283,12 +282,8 @@ describe(`onRender`, () => {
282 'read current time',
283 'read current time',
284 'read current time',
286 - 'read current time',
285 ]);
286 }
289 -
290 - // Restore original mock
291 - jest.mock('scheduler', () => jest.requireActual('scheduler/unstable_mock'));
287 });
288
289 it('does not report work done on a sibling', async () => {