Skip to content

Commit

Permalink
Switch callsites over to update lane priority
Browse files Browse the repository at this point in the history
  • Loading branch information
rickhanlonii committed Mar 8, 2021
1 parent e89d74e commit 431e76e
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 216 deletions.
19 changes: 9 additions & 10 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import type {
} from './ReactFiberHostConfig';
import type {Fiber} from './ReactInternalTypes';
import type {FiberRoot} from './ReactInternalTypes';
import type {Lanes} from './ReactFiberLane.new';
import type {LanePriority, Lanes} from './ReactFiberLane.new';
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
import type {UpdateQueue} from './ReactUpdateQueue.new';
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.new';
import type {Wakeable} from 'shared/ReactTypes';
import type {ReactPriorityLevel} from './ReactInternalTypes';
import type {OffscreenState} from './ReactFiberOffscreenComponent';
import type {HookFlags} from './ReactHookEffectTags';

Expand Down Expand Up @@ -1057,7 +1056,7 @@ function commitUnmount(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
onCommitUnmount(current);

Expand Down Expand Up @@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
finishedRoot: FiberRoot,
root: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
// While we're inside a removed host node we don't want to call
// removeChild on the inner nodes because they're removed by the top
Expand Down Expand Up @@ -1463,7 +1462,7 @@ function unmountHostComponents(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
// We only have the top Fiber that was deleted but we need to recurse down its
// children to find all the terminal nodes.
Expand Down Expand Up @@ -1601,7 +1600,7 @@ function commitDeletion(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
if (supportsMutation) {
// Recursively delete all host nodes from the parent.
Expand Down Expand Up @@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {

export function commitMutationEffects(
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
firstChild: Fiber,
) {
nextEffect = firstChild;
Expand All @@ -1954,7 +1953,7 @@ export function commitMutationEffects(

function commitMutationEffects_begin(
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
) {
while (nextEffect !== null) {
const fiber = nextEffect;
Expand Down Expand Up @@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(

function commitMutationEffects_complete(
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
) {
while (nextEffect !== null) {
const fiber = nextEffect;
Expand Down Expand Up @@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
function commitMutationEffectsOnFiber(
finishedWork: Fiber,
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
) {
const flags = finishedWork.flags;

Expand Down
19 changes: 9 additions & 10 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import type {
} from './ReactFiberHostConfig';
import type {Fiber} from './ReactInternalTypes';
import type {FiberRoot} from './ReactInternalTypes';
import type {Lanes} from './ReactFiberLane.old';
import type {LanePriority, Lanes} from './ReactFiberLane.old';
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
import type {UpdateQueue} from './ReactUpdateQueue.old';
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old';
import type {Wakeable} from 'shared/ReactTypes';
import type {ReactPriorityLevel} from './ReactInternalTypes';
import type {OffscreenState} from './ReactFiberOffscreenComponent';
import type {HookFlags} from './ReactHookEffectTags';

Expand Down Expand Up @@ -1057,7 +1056,7 @@ function commitUnmount(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
onCommitUnmount(current);

Expand Down Expand Up @@ -1153,7 +1152,7 @@ function commitNestedUnmounts(
finishedRoot: FiberRoot,
root: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
// While we're inside a removed host node we don't want to call
// removeChild on the inner nodes because they're removed by the top
Expand Down Expand Up @@ -1463,7 +1462,7 @@ function unmountHostComponents(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
// We only have the top Fiber that was deleted but we need to recurse down its
// children to find all the terminal nodes.
Expand Down Expand Up @@ -1601,7 +1600,7 @@ function commitDeletion(
finishedRoot: FiberRoot,
current: Fiber,
nearestMountedAncestor: Fiber,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
): void {
if (supportsMutation) {
// Recursively delete all host nodes from the parent.
Expand Down Expand Up @@ -1945,7 +1944,7 @@ function commitResetTextContent(current: Fiber) {

export function commitMutationEffects(
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
firstChild: Fiber,
) {
nextEffect = firstChild;
Expand All @@ -1954,7 +1953,7 @@ export function commitMutationEffects(

function commitMutationEffects_begin(
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
) {
while (nextEffect !== null) {
const fiber = nextEffect;
Expand Down Expand Up @@ -2000,7 +1999,7 @@ function commitMutationEffects_begin(

function commitMutationEffects_complete(
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
) {
while (nextEffect !== null) {
const fiber = nextEffect;
Expand Down Expand Up @@ -2041,7 +2040,7 @@ function commitMutationEffects_complete(
function commitMutationEffectsOnFiber(
finishedWork: Fiber,
root: FiberRoot,
renderPriorityLevel: ReactPriorityLevel,
renderPriorityLevel: LanePriority,
) {
const flags = finishedWork.flags;

Expand Down
19 changes: 13 additions & 6 deletions packages/react-reconciler/src/ReactFiberDevToolsHook.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

import {enableProfilerTimer} from 'shared/ReactFeatureFlags';

import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {LanePriority} from './ReactFiberLane.new';

import {DidCapture} from './ReactFiberFlags';
import {
lanePriorityToSchedulerPriority,
NoLanePriority,
} from './ReactFiberLane.new';
import {NormalPriority} from './SchedulerWithReactIntegration.new';

declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;

Expand Down Expand Up @@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
}
}

export function onCommitRoot(
root: FiberRoot,
priorityLevel: ReactPriorityLevel,
) {
export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
try {
const didError = (root.current.flags & DidCapture) === DidCapture;
if (enableProfilerTimer) {
const schedulerPriority =
priorityLevel === NoLanePriority
? NormalPriority
: lanePriorityToSchedulerPriority(priorityLevel);
injectedHook.onCommitFiberRoot(
rendererID,
root,
priorityLevel,
schedulerPriority,
didError,
);
} else {
Expand Down
19 changes: 13 additions & 6 deletions packages/react-reconciler/src/ReactFiberDevToolsHook.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@

import {enableProfilerTimer} from 'shared/ReactFeatureFlags';

import type {Fiber, FiberRoot, ReactPriorityLevel} from './ReactInternalTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {ReactNodeList} from 'shared/ReactTypes';
import type {LanePriority} from './ReactFiberLane.old';

import {DidCapture} from './ReactFiberFlags';
import {
lanePriorityToSchedulerPriority,
NoLanePriority,
} from './ReactFiberLane.old';
import {NormalPriority} from './SchedulerWithReactIntegration.old';

declare var __REACT_DEVTOOLS_GLOBAL_HOOK__: Object | void;

Expand Down Expand Up @@ -78,18 +84,19 @@ export function onScheduleRoot(root: FiberRoot, children: ReactNodeList) {
}
}

export function onCommitRoot(
root: FiberRoot,
priorityLevel: ReactPriorityLevel,
) {
export function onCommitRoot(root: FiberRoot, priorityLevel: LanePriority) {
if (injectedHook && typeof injectedHook.onCommitFiberRoot === 'function') {
try {
const didError = (root.current.flags & DidCapture) === DidCapture;
if (enableProfilerTimer) {
const schedulerPriority =
priorityLevel === NoLanePriority
? NormalPriority
: lanePriorityToSchedulerPriority(priorityLevel);
injectedHook.onCommitFiberRoot(
rendererID,
root,
priorityLevel,
schedulerPriority,
didError,
);
} else {
Expand Down
52 changes: 29 additions & 23 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

import type {Thenable, Wakeable} from 'shared/ReactTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Lanes, Lane} from './ReactFiberLane.new';
import type {ReactPriorityLevel} from './ReactInternalTypes';
import type {Lanes, Lane, LanePriority} from './ReactFiberLane.new';
import type {Interaction} from 'scheduler/src/Tracing';
import type {SuspenseState} from './ReactFiberSuspenseComponent.new';
import type {StackCursor} from './ReactFiberStack.new';
Expand Down Expand Up @@ -46,7 +45,6 @@ import {
shouldYield,
requestPaint,
now,
NoPriority as NoSchedulerPriority,
ImmediatePriority as ImmediateSchedulerPriority,
UserBlockingPriority as UserBlockingSchedulerPriority,
NormalPriority as NormalSchedulerPriority,
Expand Down Expand Up @@ -173,6 +171,7 @@ import {
markRootFinished,
schedulerPriorityToLanePriority,
lanePriorityToSchedulerPriority,
higherLanePriority,
} from './ReactFiberLane.new';
import {requestCurrentTransition, NoTransition} from './ReactFiberTransition';
import {beginWork as originalBeginWork} from './ReactFiberBeginWork.new';
Expand Down Expand Up @@ -333,7 +332,7 @@ let rootCommittingMutationOrLayoutEffects: FiberRoot | null = null;

let rootDoesHavePassiveEffects: boolean = false;
let rootWithPendingPassiveEffects: FiberRoot | null = null;
let pendingPassiveEffectsRenderPriority: ReactPriorityLevel = NoSchedulerPriority;
let pendingPassiveEffectsRenderPriority: LanePriority = NoLanePriority;
let pendingPassiveEffectsLanes: Lanes = NoLanes;
let pendingPassiveProfilerEffects: Array<Fiber> = [];

Expand Down Expand Up @@ -394,7 +393,7 @@ export function requestUpdateLane(fiber: Fiber): Lane {
if ((mode & BlockingMode) === NoMode) {
return (SyncLane: Lane);
} else if ((mode & ConcurrentMode) === NoMode) {
return getCurrentPriorityLevel() === ImmediateSchedulerPriority
return getCurrentUpdateLanePriority() === SyncLanePriority
? (SyncLane: Lane)
: (SyncBatchedLane: Lane);
} else if (
Expand Down Expand Up @@ -482,7 +481,7 @@ function requestRetryLane(fiber: Fiber) {
if ((mode & BlockingMode) === NoMode) {
return (SyncLane: Lane);
} else if ((mode & ConcurrentMode) === NoMode) {
return getCurrentPriorityLevel() === ImmediateSchedulerPriority
return getCurrentUpdateLanePriority() === SyncLanePriority
? (SyncLane: Lane)
: (SyncBatchedLane: Lane);
}
Expand Down Expand Up @@ -596,9 +595,9 @@ export function scheduleUpdateOnFiber(
// Schedule a discrete update but only if it's not Sync.
if (
(executionContext & DiscreteEventContext) !== NoContext &&
// Only updates at user-blocking priority or greater are considered
// discrete, even inside a discrete event.
updateLanePriority === InputDiscreteLanePriority
// Only updates greater than default considered discrete, even inside a discrete event.
higherLanePriority(updateLanePriority, DefaultLanePriority) !==
DefaultLanePriority
) {
// This is the result of a discrete event. Track the lowest priority
// discrete update per root so we can flush them early, if needed.
Expand Down Expand Up @@ -1751,11 +1750,17 @@ function completeUnitOfWork(unitOfWork: Fiber): void {
}

function commitRoot(root) {
const renderPriorityLevel = getCurrentPriorityLevel();
runWithPriority(
ImmediateSchedulerPriority,
commitRootImpl.bind(null, root, renderPriorityLevel),
);
const previousUpdateLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(SyncLanePriority);
runWithPriority(
ImmediateSchedulerPriority,
commitRootImpl.bind(null, root, previousUpdateLanePriority),
);
} finally {
setCurrentUpdateLanePriority(previousUpdateLanePriority);
}

return null;
}

Expand Down Expand Up @@ -1983,7 +1988,10 @@ function commitRootImpl(root, renderPriorityLevel) {
rootDoesHavePassiveEffects = false;
rootWithPendingPassiveEffects = root;
pendingPassiveEffectsLanes = lanes;
pendingPassiveEffectsRenderPriority = renderPriorityLevel;
pendingPassiveEffectsRenderPriority =
renderPriorityLevel === NoLanePriority
? DefaultLanePriority
: renderPriorityLevel;
}

// Read this again, since an effect might have updated it
Expand Down Expand Up @@ -2097,18 +2105,16 @@ function commitRootImpl(root, renderPriorityLevel) {

export function flushPassiveEffects(): boolean {
// Returns whether passive effects were flushed.
if (pendingPassiveEffectsRenderPriority !== NoSchedulerPriority) {
if (pendingPassiveEffectsRenderPriority !== NoLanePriority) {
const priorityLevel =
pendingPassiveEffectsRenderPriority > NormalSchedulerPriority
? NormalSchedulerPriority
pendingPassiveEffectsRenderPriority > DefaultLanePriority
? DefaultLanePriority
: pendingPassiveEffectsRenderPriority;
pendingPassiveEffectsRenderPriority = NoSchedulerPriority;
pendingPassiveEffectsRenderPriority = NoLanePriority;
const previousLanePriority = getCurrentUpdateLanePriority();
try {
setCurrentUpdateLanePriority(
schedulerPriorityToLanePriority(priorityLevel),
);
return runWithPriority(priorityLevel, flushPassiveEffectsImpl);
setCurrentUpdateLanePriority(priorityLevel);
return flushPassiveEffectsImpl();
} finally {
setCurrentUpdateLanePriority(previousLanePriority);
}
Expand Down
Loading

0 comments on commit 431e76e

Please sign in to comment.