Skip to content

Commit

Permalink
Avoid dynamic dispatch for scheduler calls (#14968)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored Mar 1, 2019
1 parent bb2939c commit 02404d7
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 89 deletions.
22 changes: 12 additions & 10 deletions packages/react-art/src/ReactARTHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,24 @@
* LICENSE file in the root directory of this source tree.
*/

import {
unstable_scheduleCallback as scheduleDeferredCallback,
unstable_cancelCallback as cancelDeferredCallback,
} from 'scheduler';
export {
unstable_now as now,
unstable_scheduleCallback as scheduleDeferredCallback,
unstable_shouldYield as shouldYield,
unstable_cancelCallback as cancelDeferredCallback,
} from 'scheduler';
import Transform from 'art/core/transform';
import Mode from 'art/modes/current';
import * as Scheduler from 'scheduler';
import invariant from 'shared/invariant';

import {TYPES, EVENT_TYPES, childrenAsString} from './ReactARTInternals';

// Intentionally not named imports because Rollup would
// use dynamic dispatch for CommonJS interop named imports.
const {
unstable_now: now,
unstable_scheduleCallback: scheduleDeferredCallback,
unstable_shouldYield: shouldYield,
unstable_cancelCallback: cancelDeferredCallback,
} = Scheduler;

export {now, scheduleDeferredCallback, shouldYield, cancelDeferredCallback};

const pooledTransform = new Transform();

const NO_CONTEXT = {};
Expand Down
6 changes: 5 additions & 1 deletion packages/react-cache/src/LRU.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@
* @flow
*/

import {unstable_scheduleCallback as scheduleCallback} from 'scheduler';
import * as Scheduler from 'scheduler';

// Intentionally not named imports because Rollup would
// use dynamic dispatch for CommonJS interop named imports.
const {unstable_scheduleCallback: scheduleCallback} = Scheduler;

type Entry<T> = {|
value: T,
Expand Down
23 changes: 13 additions & 10 deletions packages/react-dom/src/client/ReactDOMHostConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
* @flow
*/

import * as Scheduler from 'scheduler';

import {precacheFiberNode, updateFiberProps} from './ReactDOMComponentTree';
import {
createElement,
Expand Down Expand Up @@ -70,17 +72,18 @@ export type ChildSet = void; // Unused
export type TimeoutHandle = TimeoutID;
export type NoTimeout = -1;

import {
unstable_scheduleCallback as scheduleDeferredCallback,
unstable_cancelCallback as cancelDeferredCallback,
} from 'scheduler';
import {enableSuspenseServerRenderer} from 'shared/ReactFeatureFlags';
export {
unstable_now as now,
unstable_scheduleCallback as scheduleDeferredCallback,
unstable_shouldYield as shouldYield,
unstable_cancelCallback as cancelDeferredCallback,
} from 'scheduler';

// Intentionally not named imports because Rollup would
// use dynamic dispatch for CommonJS interop named imports.
const {
unstable_now: now,
unstable_scheduleCallback: scheduleDeferredCallback,
unstable_shouldYield: shouldYield,
unstable_cancelCallback: cancelDeferredCallback,
} = Scheduler;

export {now, scheduleDeferredCallback, shouldYield, cancelDeferredCallback};

let SUPPRESS_HYDRATION_WARNING;
if (__DEV__) {
Expand Down
24 changes: 14 additions & 10 deletions packages/react-reconciler/src/ReactFiberScheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,7 @@ import {
__subscriberRef,
unstable_wrap as Scheduler_tracing_wrap,
} from 'scheduler/tracing';
import {
unstable_next as Scheduler_next,
unstable_getCurrentPriorityLevel as getCurrentPriorityLevel,
unstable_runWithPriority as runWithPriority,
unstable_ImmediatePriority as ImmediatePriority,
unstable_UserBlockingPriority as UserBlockingPriority,
unstable_NormalPriority as NormalPriority,
unstable_LowPriority as LowPriority,
unstable_IdlePriority as IdlePriority,
} from 'scheduler';
import * as Scheduler from 'scheduler';
import {
invokeGuardedCallback,
hasCaughtError,
Expand Down Expand Up @@ -181,6 +172,19 @@ export type Thenable = {
then(resolve: () => mixed, reject?: () => mixed): mixed,
};

// Intentionally not named imports because Rollup would
// use dynamic dispatch for CommonJS interop named imports.
const {
unstable_next: Scheduler_next,
unstable_getCurrentPriorityLevel: getCurrentPriorityLevel,
unstable_runWithPriority: runWithPriority,
unstable_ImmediatePriority: ImmediatePriority,
unstable_UserBlockingPriority: UserBlockingPriority,
unstable_NormalPriority: NormalPriority,
unstable_LowPriority: LowPriority,
unstable_IdlePriority: IdlePriority,
} = Scheduler;

const {ReactCurrentDispatcher, ReactCurrentOwner} = ReactSharedInternals;

let didWarnAboutStateTransition;
Expand Down
62 changes: 4 additions & 58 deletions packages/react/src/ReactSharedInternals.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,8 @@
*/

import assign from 'object-assign';
import {
unstable_cancelCallback,
unstable_shouldYield,
unstable_now,
unstable_scheduleCallback,
unstable_runWithPriority,
unstable_next,
unstable_getFirstCallbackNode,
unstable_pauseExecution,
unstable_continueExecution,
unstable_wrapCallback,
unstable_getCurrentPriorityLevel,
unstable_IdlePriority,
unstable_ImmediatePriority,
unstable_LowPriority,
unstable_NormalPriority,
unstable_UserBlockingPriority,
} from 'scheduler';
import {
__interactionsRef,
__subscriberRef,
unstable_clear,
unstable_getCurrent,
unstable_getThreadID,
unstable_subscribe,
unstable_trace,
unstable_unsubscribe,
unstable_wrap,
} from 'scheduler/tracing';
import * as Scheduler from 'scheduler';
import * as SchedulerTracing from 'scheduler/tracing';
import ReactCurrentDispatcher from './ReactCurrentDispatcher';
import ReactCurrentOwner from './ReactCurrentOwner';
import ReactDebugCurrentFrame from './ReactDebugCurrentFrame';
Expand All @@ -53,35 +26,8 @@ if (__UMD__) {
// This re-export is only required for UMD bundles;
// CJS bundles use the shared NPM package.
Object.assign(ReactSharedInternals, {
Scheduler: {
unstable_cancelCallback,
unstable_shouldYield,
unstable_now,
unstable_scheduleCallback,
unstable_runWithPriority,
unstable_next,
unstable_wrapCallback,
unstable_getFirstCallbackNode,
unstable_pauseExecution,
unstable_continueExecution,
unstable_getCurrentPriorityLevel,
unstable_IdlePriority,
unstable_ImmediatePriority,
unstable_LowPriority,
unstable_NormalPriority,
unstable_UserBlockingPriority,
},
SchedulerTracing: {
__interactionsRef,
__subscriberRef,
unstable_clear,
unstable_getCurrent,
unstable_getThreadID,
unstable_subscribe,
unstable_trace,
unstable_unsubscribe,
unstable_wrap,
},
Scheduler,
SchedulerTracing,
});
}

Expand Down

0 comments on commit 02404d7

Please sign in to comment.