Skip to content

Commit

Permalink
Sync scheduling profiler marks and debug tracing to new reconciler fo…
Browse files Browse the repository at this point in the history
…rk (#19375, #19376, #19396)

* Make enableSchedulingProfiler flag static

* Copied debug tracing and scheduler profiling to .new fork and updated feature flags

* Move profiler component stacks behind a feature flag
  • Loading branch information
Brian Vaughn committed Jul 17, 2020
1 parent aec934a commit 51267c4
Show file tree
Hide file tree
Showing 17 changed files with 382 additions and 46 deletions.
48 changes: 47 additions & 1 deletion packages/react-reconciler/src/ReactFiberClassComponent.new.js
Expand Up @@ -16,6 +16,8 @@ import {Update, Snapshot} from './ReactSideEffectTags';
import {
debugRenderPhaseSideEffectsForStrictMode,
disableLegacyContext,
enableDebugTracing,
enableSchedulingProfiler,
warnAboutDeprecatedLifecycles,
} from 'shared/ReactFeatureFlags';
import ReactStrictModeWarnings from './ReactStrictModeWarnings.new';
Expand All @@ -27,7 +29,7 @@ import invariant from 'shared/invariant';
import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols';

import {resolveDefaultProps} from './ReactFiberLazyComponent.new';
import {StrictMode} from './ReactTypeOfMode';
import {DebugTracingMode, StrictMode} from './ReactTypeOfMode';

import {
enqueueUpdate,
Expand Down Expand Up @@ -55,8 +57,13 @@ import {
scheduleUpdateOnFiber,
} from './ReactFiberWorkLoop.new';
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing';

import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
import {
markForceUpdateScheduled,
markStateUpdateScheduled,
} from './SchedulingProfiler';

const fakeInternalInstance = {};
const isArray = Array.isArray;
Expand Down Expand Up @@ -203,6 +210,19 @@ const classComponentUpdater = {

enqueueUpdate(fiber, update);
scheduleUpdateOnFiber(fiber, lane, eventTime);

if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
const name = getComponentName(fiber.type) || 'Unknown';
logStateUpdateScheduled(name, lane, payload);
}
}
}

if (enableSchedulingProfiler) {
markStateUpdateScheduled(fiber, lane);
}
},
enqueueReplaceState(inst, payload, callback) {
const fiber = getInstance(inst);
Expand All @@ -223,6 +243,19 @@ const classComponentUpdater = {

enqueueUpdate(fiber, update);
scheduleUpdateOnFiber(fiber, lane, eventTime);

if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
const name = getComponentName(fiber.type) || 'Unknown';
logStateUpdateScheduled(name, lane, payload);
}
}
}

if (enableSchedulingProfiler) {
markStateUpdateScheduled(fiber, lane);
}
},
enqueueForceUpdate(inst, callback) {
const fiber = getInstance(inst);
Expand All @@ -242,6 +275,19 @@ const classComponentUpdater = {

enqueueUpdate(fiber, update);
scheduleUpdateOnFiber(fiber, lane, eventTime);

if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
const name = getComponentName(fiber.type) || 'Unknown';
logForceUpdateScheduled(name, lane);
}
}
}

if (enableSchedulingProfiler) {
markForceUpdateScheduled(fiber, lane);
}
},
};

Expand Down
23 changes: 21 additions & 2 deletions packages/react-reconciler/src/ReactFiberHooks.new.js
Expand Up @@ -24,9 +24,13 @@ import type {FiberRoot} from './ReactInternalTypes';
import type {OpaqueIDType} from './ReactFiberHostConfig';

import ReactSharedInternals from 'shared/ReactSharedInternals';
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
import {
enableDebugTracing,
enableSchedulingProfiler,
enableNewReconciler,
} from 'shared/ReactFeatureFlags';

import {NoMode, BlockingMode} from './ReactTypeOfMode';
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
import {
NoLane,
NoLanes,
Expand Down Expand Up @@ -88,6 +92,8 @@ import {
warnAboutMultipleRenderersDEV,
} from './ReactMutableSource.new';
import {getIsRendering} from './ReactCurrentFiber';
import {logStateUpdateScheduled} from './DebugTracing';
import {markStateUpdateScheduled} from './SchedulingProfiler';

const {ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals;

Expand Down Expand Up @@ -1751,6 +1757,19 @@ function dispatchAction<S, A>(
}
scheduleUpdateOnFiber(fiber, lane, eventTime);
}

if (__DEV__) {
if (enableDebugTracing) {
if (fiber.mode & DebugTracingMode) {
const name = getComponentName(fiber.type) || 'Unknown';
logStateUpdateScheduled(name, lane, action);
}
}
}

if (enableSchedulingProfiler) {
markStateUpdateScheduled(fiber, lane);
}
}

export const ContextOnlyDispatcher: Dispatcher = {
Expand Down
6 changes: 6 additions & 0 deletions packages/react-reconciler/src/ReactFiberReconciler.new.js
Expand Up @@ -39,6 +39,7 @@ import {
} from './ReactWorkTags';
import getComponentName from 'shared/getComponentName';
import invariant from 'shared/invariant';
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
import ReactSharedInternals from 'shared/ReactSharedInternals';
import {getPublicInstance} from './ReactFiberHostConfig';
import {
Expand Down Expand Up @@ -95,6 +96,7 @@ import {
setRefreshHandler,
findHostInstancesForRefresh,
} from './ReactFiberHotReloading.new';
import {markRenderScheduled} from './SchedulingProfiler';

export {registerMutableSourceForHydration} from './ReactMutableSource.new';
export {createPortal} from './ReactPortal';
Expand Down Expand Up @@ -273,6 +275,10 @@ export function updateContainer(
const suspenseConfig = requestCurrentSuspenseConfig();
const lane = requestUpdateLane(current, suspenseConfig);

if (enableSchedulingProfiler) {
markRenderScheduled(lane);
}

const context = getContextForSubtree(parentComponent);
if (container.context === null) {
container.context = context;
Expand Down
21 changes: 20 additions & 1 deletion packages/react-reconciler/src/ReactFiberThrow.new.js
Expand Up @@ -31,7 +31,11 @@ import {
ForceUpdateForLegacySuspense,
} from './ReactSideEffectTags';
import {shouldCaptureSuspense} from './ReactFiberSuspenseComponent.new';
import {NoMode, BlockingMode} from './ReactTypeOfMode';
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
import {
enableDebugTracing,
enableSchedulingProfiler,
} from 'shared/ReactFeatureFlags';
import {createCapturedValue} from './ReactCapturedValue';
import {
enqueueCapturedUpdate,
Expand All @@ -54,6 +58,8 @@ import {
pingSuspendedRoot,
} from './ReactFiberWorkLoop.new';
import {logCapturedError} from './ReactFiberErrorLogger';
import {logComponentSuspended} from './DebugTracing';
import {markComponentSuspended} from './SchedulingProfiler';

import {
SyncLane,
Expand Down Expand Up @@ -190,6 +196,19 @@ function throwException(
// This is a wakeable.
const wakeable: Wakeable = (value: any);

if (__DEV__) {
if (enableDebugTracing) {
if (sourceFiber.mode & DebugTracingMode) {
const name = getComponentName(sourceFiber.type) || 'Unknown';
logComponentSuspended(name, wakeable);
}
}
}

if (enableSchedulingProfiler) {
markComponentSuspended(sourceFiber, wakeable);
}

if ((sourceFiber.mode & BlockingMode) === NoMode) {
// Reset the memoizedState to what it was before we attempted
// to render it.
Expand Down

0 comments on commit 51267c4

Please sign in to comment.