Skip to content

Commit

Permalink
Renamed schedulers to updaters
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn committed May 16, 2019
1 parent 6d84e3c commit 813348d
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 68 deletions.
10 changes: 5 additions & 5 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
enableSchedulerTracing,
enableProfilerTimer,
enableSuspenseServerRenderer,
enableUpdateSchedulerTracking,
enableUpdaterTracking,
enableEventAPI,
} from 'shared/ReactFeatureFlags';
import {
Expand Down Expand Up @@ -105,7 +105,7 @@ import {
captureCommitPhaseError,
requestCurrentTime,
resolveRetryThenable,
restorePendingSchedulers,
restorePendingUpdaters,
} from './ReactFiberScheduler';
import {
NoEffect as NoHookEffect,
Expand Down Expand Up @@ -1346,9 +1346,9 @@ function commitSuspenseComponent(
if (enableSchedulerTracing) {
retry = Schedule_tracing_wrap(retry);
}
if (enableUpdateSchedulerTracking) {
// If we have pending work still, restore the original schedulers
restorePendingSchedulers(finishedRoot, committedExpirationTime);
if (enableUpdaterTracking) {
// If we have pending work still, restore the original updaters
restorePendingUpdaters(finishedRoot, committedExpirationTime);
}
retryCache.add(thenable);
thenable.then(retry, retry);
Expand Down
20 changes: 10 additions & 10 deletions packages/react-reconciler/src/ReactFiberRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {createHostRootFiber} from './ReactFiber';
import {NoWork} from './ReactFiberExpirationTime';
import {
enableSchedulerTracing,
enableUpdateSchedulerTracking,
enableUpdaterTracking,
} from 'shared/ReactFeatureFlags';
import {unstable_getThreadID} from 'scheduler/tracing';

Expand All @@ -33,8 +33,8 @@ export type Batch = {

export type PendingInteractionMap = Map<ExpirationTime, Set<Interaction>>;

// Map of expiration time to all pending "schedulers" which in turn is a map of Fibers to reference counts.
export type PendingSchedulersMap = Map<ExpirationTime, Set<Fiber>>;
// Map of expiration time to all pending "updaters" which in turn is a map of Fibers to reference counts.
export type PendingUpdatersMap = Map<ExpirationTime, Set<Fiber>>;

type BaseFiberRootProperties = {|
// The type of root (legacy, batched, concurrent, etc.)
Expand Down Expand Up @@ -91,9 +91,9 @@ type ProfilingOnlyFiberRootProperties = {|

// The following attributes are only used by DevTools and are only present in DEV builds.
// They enable DevTools Profiler UI to show which Fiber(s) scheduled a given commit.
type SchedulerTrackingOnlyFiberRootProperties = {|
memoizedSchedulers: Set<Fiber>,
pendingSchedulersMap: PendingSchedulersMap,
type UpdaterTrackingOnlyFiberRootProperties = {|
memoizedUpdaters: Set<Fiber>,
pendingUpdatersMap: PendingUpdatersMap,
|};

// Exported FiberRoot type includes all properties,
Expand All @@ -104,7 +104,7 @@ type SchedulerTrackingOnlyFiberRootProperties = {|
export type FiberRoot = {
...BaseFiberRootProperties,
...ProfilingOnlyFiberRootProperties,
...SchedulerTrackingOnlyFiberRootProperties,
...UpdaterTrackingOnlyFiberRootProperties,
};

function FiberRootNode(containerInfo, tag, hydrate) {
Expand Down Expand Up @@ -132,9 +132,9 @@ function FiberRootNode(containerInfo, tag, hydrate) {
this.pendingInteractionMap = new Map();
}

if (enableUpdateSchedulerTracking) {
this.memoizedSchedulers = new Set();
this.pendingSchedulersMap = new Map();
if (enableUpdaterTracking) {
this.memoizedUpdaters = new Set();
this.pendingUpdatersMap = new Map();
}
}

Expand Down
50 changes: 25 additions & 25 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import type {Interaction} from 'scheduler/src/Tracing';
import {
warnAboutDeprecatedLifecycles,
enableUserTimingAPI,
enableUpdateSchedulerTracking,
enableUpdaterTracking,
enableSuspenseServerRenderer,
replayFailedUnitOfWorkWithInvokeGuardedCallback,
enableProfilerTimer,
Expand Down Expand Up @@ -337,14 +337,14 @@ export function scheduleUpdateOnFiber(
return;
}

if (enableUpdateSchedulerTracking) {
const pendingSchedulersMap = root.pendingSchedulersMap;
let schedulers = pendingSchedulersMap.get(expirationTime);
if (schedulers == null) {
schedulers = new Set();
pendingSchedulersMap.set(expirationTime, schedulers);
if (enableUpdaterTracking) {
const pendingUpdatersMap = root.pendingUpdatersMap;
let updaters = pendingUpdatersMap.get(expirationTime);
if (updaters == null) {
updaters = new Set();
pendingUpdatersMap.set(expirationTime, updaters);
}
schedulers.add(fiber);
updaters.add(fiber);
}

root.pingTime = NoWork;
Expand Down Expand Up @@ -1296,7 +1296,7 @@ function commitRootImpl(root) {

if (enableSchedulerTracing) {
if (firstPendingTimeBeforeCommit !== NoWork) {
restorePendingSchedulers(root, root.lastPendingTime);
restorePendingUpdaters(root, root.lastPendingTime);
}
}
}
Expand Down Expand Up @@ -2182,21 +2182,21 @@ function warnIfNotCurrentlyActingUpdatesInDEV(fiber: Fiber): void {
}
}

export function restorePendingSchedulers(
export function restorePendingUpdaters(
root: FiberRoot,
expirationTime: ExpirationTime,
): void {
if (!enableUpdateSchedulerTracking) {
if (!enableUpdaterTracking) {
return;
}
const pendingSchedulersMap = root.pendingSchedulersMap;
let schedulers = pendingSchedulersMap.get(expirationTime);
if (schedulers == null) {
schedulers = new Set();
pendingSchedulersMap.set(expirationTime, schedulers);
const pendingUpdatersMap = root.pendingUpdatersMap;
let updaters = pendingUpdatersMap.get(expirationTime);
if (updaters == null) {
updaters = new Set();
pendingUpdatersMap.set(expirationTime, updaters);
}
root.memoizedSchedulers.forEach(schedulingFiber => {
((schedulers: any): Set<Fiber>).add(schedulingFiber);
root.memoizedUpdaters.forEach(schedulingFiber => {
((updaters: any): Set<Fiber>).add(schedulingFiber);
});
}

Expand Down Expand Up @@ -2317,21 +2317,21 @@ function schedulePendingInteraction(root, expirationTime) {
function startWorkOnPendingInteraction(root, expirationTime) {
// This is called when new work is started on a root.

if (enableUpdateSchedulerTracking) {
const memoizedSchedulers: Set<Fiber> = new Set();
const pendingSchedulersMap = root.pendingSchedulersMap;
pendingSchedulersMap.forEach((schedulers, scheduledExpirationTime) => {
if (enableUpdaterTracking) {
const memoizedUpdaters: Set<Fiber> = new Set();
const pendingUpdatersMap = root.pendingUpdatersMap;
pendingUpdatersMap.forEach((updaters, scheduledExpirationTime) => {
if (scheduledExpirationTime >= expirationTime) {
pendingSchedulersMap.delete(scheduledExpirationTime);
schedulers.forEach(fiber => memoizedSchedulers.add(fiber));
pendingUpdatersMap.delete(scheduledExpirationTime);
updaters.forEach(fiber => memoizedUpdaters.add(fiber));
}
});

// Store the current set of interactions on the FiberRoot for a few reasons:
// We can re-use it in hot functions like renderRoot() without having to
// recalculate it. This also provides DevTools with a way to access it when
// the onCommitRoot() hook is called.
root.memoizedSchedulers = memoizedSchedulers;
root.memoizedUpdaters = memoizedUpdaters;
}

if (enableSchedulerTracing) {
Expand Down
16 changes: 8 additions & 8 deletions packages/react-reconciler/src/ReactFiberUnwindWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import {
import {
enableSchedulerTracing,
enableSuspenseServerRenderer,
enableUpdateSchedulerTracking,
enableUpdaterTracking,
enableEventAPI,
} from 'shared/ReactFeatureFlags';
import {NoMode, BatchedMode} from './ReactTypeOfMode';
Expand Down Expand Up @@ -77,7 +77,7 @@ import {
pingSuspendedRoot,
resolveRetryThenable,
checkForWrongSuspensePriorityInDEV,
restorePendingSchedulers,
restorePendingUpdaters,
} from './ReactFiberScheduler';

import invariant from 'shared/invariant';
Expand Down Expand Up @@ -189,9 +189,9 @@ function attachPingListener(
if (enableSchedulerTracing) {
ping = Schedule_tracing_wrap(ping);
}
if (enableUpdateSchedulerTracking) {
// If we have pending work still, restore the original schedulers
restorePendingSchedulers(root, renderExpirationTime);
if (enableUpdaterTracking) {
// If we have pending work still, restore the original updaters
restorePendingUpdaters(root, renderExpirationTime);
}
thenable.then(ping, ping);
}
Expand All @@ -209,9 +209,9 @@ function throwException(
// Its effect list is no longer valid.
sourceFiber.firstEffect = sourceFiber.lastEffect = null;

if (enableUpdateSchedulerTracking) {
// If we have pending work still, restore the original schedulers
restorePendingSchedulers(root, renderExpirationTime);
if (enableUpdaterTracking) {
// If we have pending work still, restore the original updaters
restorePendingUpdaters(root, renderExpirationTime);
}

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let mockDevToolsHook;
let allSchedulerTags;
let allSchedulerTypes;

describe('schedulers', () => {
describe('updaters', () => {
beforeEach(() => {
jest.resetModules();

Expand All @@ -31,7 +31,7 @@ describe('schedulers', () => {
Scheduler.yieldValue('onCommitRoot');
const schedulerTags = [];
const schedulerTypes = [];
fiberRoot.memoizedSchedulers.forEach(fiber => {
fiberRoot.memoizedUpdaters.forEach(fiber => {
schedulerTags.push(fiber.tag);
schedulerTypes.push(fiber.elementType);
});
Expand All @@ -48,7 +48,7 @@ describe('schedulers', () => {
);

ReactFeatureFlags = require('shared/ReactFeatureFlags');
ReactFeatureFlags.enableUpdateSchedulerTracking = true;
ReactFeatureFlags.enableUpdaterTracking = true;
ReactFeatureFlags.debugRenderPhaseSideEffectsForStrictMode = false;

React = require('react');
Expand Down Expand Up @@ -221,9 +221,6 @@ describe('schedulers', () => {
expect(allSchedulerTypes[4]).toHaveLength(1);
expect(allSchedulerTypes[4]).toContain(CascadingChild);

// Question: Should SchedulingComponent also be reported for the cascading updates?
// I have mixed feelings about this; it's easier not to include it so...

// Verify no outstanding flushes
Scheduler.flushAll();
});
Expand Down Expand Up @@ -397,9 +394,7 @@ describe('schedulers', () => {
mockDevToolsHook.onCommitRoot.mockImplementation(fiberRoot => {
Scheduler.yieldValue('onCommitRoot');
schedulerTypes.push(
Array.from(fiberRoot.memoizedSchedulers).map(
fiber => fiber.elementType,
),
Array.from(fiberRoot.memoizedUpdaters).map(fiber => fiber.elementType),
);
});

Expand All @@ -417,14 +412,11 @@ describe('schedulers', () => {
expect(schedulerTypes[1]).toHaveLength(1);
expect(schedulerTypes[1]).toContain(ErrorBoundary);

// Question: Should Parent also be reported in the second schedulers set?
// I have mixed feelings about this; it's easier not to include it so...

// Verify no outstanding flushes
Scheduler.flushAll();
});

it('should distinguish between schedulers in the case of interleaved work', () => {
it('should distinguish between updaters in the case of interleaved work', () => {
let triggerLowPriorityUpdate = null;
let triggerSyncPriorityUpdate = null;

Expand Down
2 changes: 1 addition & 1 deletion packages/shared/ReactFeatureFlags.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;

// Track which Fiber(s) schedule render work.
export const enableUpdateSchedulerTracking = __PROFILE__;
export const enableUpdaterTracking = __PROFILE__;

// Only used in www builds.
export const enableSuspenseServerRenderer = false; // TODO: __DEV__? Here it might just be false.
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.native-fb.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const {debugRenderPhaseSideEffects} = require('ReactFeatureFlags');
export const enableUserTimingAPI = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableUpdateSchedulerTracking = __PROFILE__;
export const enableUpdaterTracking = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const enableStableConcurrentModeAPIs = false;
export const warnAboutShorthandPropertyCollision = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.native-oss.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const warnAboutDeprecatedLifecycles = true;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableUpdateSchedulerTracking = __PROFILE__;
export const enableUpdaterTracking = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const disableJavaScriptURLs = false;
export const disableYielding = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.persistent.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const warnAboutDeprecatedLifecycles = true;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = __DEV__;
export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableUpdateSchedulerTracking = __PROFILE__;
export const enableUpdaterTracking = __PROFILE__;
export const enableSuspenseServerRenderer = false;
export const disableJavaScriptURLs = false;
export const disableYielding = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.test-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const warnAboutDeprecatedLifecycles = false;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const enableSchedulerTracing = false;
export const enableUpdateSchedulerTracking = false;
export const enableUpdaterTracking = false;
export const enableSuspenseServerRenderer = false;
export const disableJavaScriptURLs = false;
export const disableYielding = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const warnAboutDeprecatedLifecycles = true;
export const replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
export const enableProfilerTimer = false;
export const enableSchedulerTracing = false;
export const enableUpdateSchedulerTracking = false;
export const enableUpdaterTracking = false;
export const enableSuspenseServerRenderer = false;
export const enableStableConcurrentModeAPIs = false;
export const enableSchedulerDebugging = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/shared/forks/ReactFeatureFlags.www.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export let enableUserTimingAPI = __DEV__;

export const enableProfilerTimer = __PROFILE__;
export const enableSchedulerTracing = __PROFILE__;
export const enableUpdateSchedulerTracking = __PROFILE__;
export const enableUpdaterTracking = __PROFILE__;
export const enableSchedulerDebugging = true;

export const enableStableConcurrentModeAPIs = false;
Expand Down

0 comments on commit 813348d

Please sign in to comment.