Skip to content

Commit 6d7555b

Browse files
author
Brian Vaughn
authored
Scheduling profiler updates (facebook#19334)
* Make enableSchedulingProfiler static for profiling+experimental builds * Copied debug tracing and scheduler profiling to .new fork * Updated test @GATE conditions
1 parent 9ea0f67 commit 6d7555b

10 files changed

+269
-15
lines changed

packages/react-reconciler/src/ReactFiberClassComponent.new.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ import {Update, Snapshot} from './ReactSideEffectTags';
1616
import {
1717
debugRenderPhaseSideEffectsForStrictMode,
1818
disableLegacyContext,
19+
enableDebugTracing,
20+
enableSchedulingProfiler,
1921
warnAboutDeprecatedLifecycles,
2022
} from 'shared/ReactFeatureFlags';
2123
import ReactStrictModeWarnings from './ReactStrictModeWarnings.new';
@@ -27,7 +29,7 @@ import invariant from 'shared/invariant';
2729
import {REACT_CONTEXT_TYPE, REACT_PROVIDER_TYPE} from 'shared/ReactSymbols';
2830

2931
import {resolveDefaultProps} from './ReactFiberLazyComponent.new';
30-
import {StrictMode} from './ReactTypeOfMode';
32+
import {DebugTracingMode, StrictMode} from './ReactTypeOfMode';
3133

3234
import {
3335
enqueueUpdate,
@@ -55,8 +57,13 @@ import {
5557
scheduleUpdateOnFiber,
5658
} from './ReactFiberWorkLoop.new';
5759
import {requestCurrentSuspenseConfig} from './ReactFiberSuspenseConfig';
60+
import {logForceUpdateScheduled, logStateUpdateScheduled} from './DebugTracing';
5861

5962
import {disableLogs, reenableLogs} from 'shared/ConsolePatchingDev';
63+
import {
64+
markForceUpdateScheduled,
65+
markStateUpdateScheduled,
66+
} from './SchedulingProfiler';
6067

6168
const fakeInternalInstance = {};
6269
const isArray = Array.isArray;
@@ -203,6 +210,19 @@ const classComponentUpdater = {
203210

204211
enqueueUpdate(fiber, update);
205212
scheduleUpdateOnFiber(fiber, lane, eventTime);
213+
214+
if (__DEV__) {
215+
if (enableDebugTracing) {
216+
if (fiber.mode & DebugTracingMode) {
217+
const name = getComponentName(fiber.type) || 'Unknown';
218+
logStateUpdateScheduled(name, lane, payload);
219+
}
220+
}
221+
}
222+
223+
if (enableSchedulingProfiler) {
224+
markStateUpdateScheduled(fiber, lane);
225+
}
206226
},
207227
enqueueReplaceState(inst, payload, callback) {
208228
const fiber = getInstance(inst);
@@ -223,6 +243,19 @@ const classComponentUpdater = {
223243

224244
enqueueUpdate(fiber, update);
225245
scheduleUpdateOnFiber(fiber, lane, eventTime);
246+
247+
if (__DEV__) {
248+
if (enableDebugTracing) {
249+
if (fiber.mode & DebugTracingMode) {
250+
const name = getComponentName(fiber.type) || 'Unknown';
251+
logStateUpdateScheduled(name, lane, payload);
252+
}
253+
}
254+
}
255+
256+
if (enableSchedulingProfiler) {
257+
markStateUpdateScheduled(fiber, lane);
258+
}
226259
},
227260
enqueueForceUpdate(inst, callback) {
228261
const fiber = getInstance(inst);
@@ -242,6 +275,19 @@ const classComponentUpdater = {
242275

243276
enqueueUpdate(fiber, update);
244277
scheduleUpdateOnFiber(fiber, lane, eventTime);
278+
279+
if (__DEV__) {
280+
if (enableDebugTracing) {
281+
if (fiber.mode & DebugTracingMode) {
282+
const name = getComponentName(fiber.type) || 'Unknown';
283+
logForceUpdateScheduled(name, lane);
284+
}
285+
}
286+
}
287+
288+
if (enableSchedulingProfiler) {
289+
markForceUpdateScheduled(fiber, lane);
290+
}
245291
},
246292
};
247293

packages/react-reconciler/src/ReactFiberHooks.new.js

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,13 @@ import type {FiberRoot} from './ReactInternalTypes';
2424
import type {OpaqueIDType} from './ReactFiberHostConfig';
2525

2626
import ReactSharedInternals from 'shared/ReactSharedInternals';
27-
import {enableNewReconciler} from 'shared/ReactFeatureFlags';
27+
import {
28+
enableDebugTracing,
29+
enableSchedulingProfiler,
30+
enableNewReconciler,
31+
} from 'shared/ReactFeatureFlags';
2832

29-
import {NoMode, BlockingMode} from './ReactTypeOfMode';
33+
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
3034
import {
3135
NoLane,
3236
NoLanes,
@@ -88,6 +92,8 @@ import {
8892
warnAboutMultipleRenderersDEV,
8993
} from './ReactMutableSource.new';
9094
import {getIsRendering} from './ReactCurrentFiber';
95+
import {logStateUpdateScheduled} from './DebugTracing';
96+
import {markStateUpdateScheduled} from './SchedulingProfiler';
9197

9298
const {ReactCurrentDispatcher, ReactCurrentBatchConfig} = ReactSharedInternals;
9399

@@ -1751,6 +1757,19 @@ function dispatchAction<S, A>(
17511757
}
17521758
scheduleUpdateOnFiber(fiber, lane, eventTime);
17531759
}
1760+
1761+
if (__DEV__) {
1762+
if (enableDebugTracing) {
1763+
if (fiber.mode & DebugTracingMode) {
1764+
const name = getComponentName(fiber.type) || 'Unknown';
1765+
logStateUpdateScheduled(name, lane, action);
1766+
}
1767+
}
1768+
}
1769+
1770+
if (enableSchedulingProfiler) {
1771+
markStateUpdateScheduled(fiber, lane);
1772+
}
17541773
}
17551774

17561775
export const ContextOnlyDispatcher: Dispatcher = {

packages/react-reconciler/src/ReactFiberReconciler.new.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
} from './ReactWorkTags';
4040
import getComponentName from 'shared/getComponentName';
4141
import invariant from 'shared/invariant';
42+
import {enableSchedulingProfiler} from 'shared/ReactFeatureFlags';
4243
import ReactSharedInternals from 'shared/ReactSharedInternals';
4344
import {getPublicInstance} from './ReactFiberHostConfig';
4445
import {
@@ -95,6 +96,7 @@ import {
9596
setRefreshHandler,
9697
findHostInstancesForRefresh,
9798
} from './ReactFiberHotReloading.new';
99+
import {markRenderScheduled} from './SchedulingProfiler';
98100

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

278+
if (enableSchedulingProfiler) {
279+
markRenderScheduled(lane);
280+
}
281+
276282
const context = getContextForSubtree(parentComponent);
277283
if (container.context === null) {
278284
container.context = context;

packages/react-reconciler/src/ReactFiberThrow.new.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ import {
3131
ForceUpdateForLegacySuspense,
3232
} from './ReactSideEffectTags';
3333
import {shouldCaptureSuspense} from './ReactFiberSuspenseComponent.new';
34-
import {NoMode, BlockingMode} from './ReactTypeOfMode';
34+
import {NoMode, BlockingMode, DebugTracingMode} from './ReactTypeOfMode';
35+
import {
36+
enableDebugTracing,
37+
enableSchedulingProfiler,
38+
} from 'shared/ReactFeatureFlags';
3539
import {createCapturedValue} from './ReactCapturedValue';
3640
import {
3741
enqueueCapturedUpdate,
@@ -54,6 +58,8 @@ import {
5458
pingSuspendedRoot,
5559
} from './ReactFiberWorkLoop.new';
5660
import {logCapturedError} from './ReactFiberErrorLogger';
61+
import {logComponentSuspended} from './DebugTracing';
62+
import {markComponentSuspended} from './SchedulingProfiler';
5763

5864
import {
5965
SyncLane,
@@ -190,6 +196,19 @@ function throwException(
190196
// This is a wakeable.
191197
const wakeable: Wakeable = (value: any);
192198

199+
if (__DEV__) {
200+
if (enableDebugTracing) {
201+
if (sourceFiber.mode & DebugTracingMode) {
202+
const name = getComponentName(sourceFiber.type) || 'Unknown';
203+
logComponentSuspended(name, wakeable);
204+
}
205+
}
206+
}
207+
208+
if (enableSchedulingProfiler) {
209+
markComponentSuspended(sourceFiber, wakeable);
210+
}
211+
193212
if ((sourceFiber.mode & BlockingMode) === NoMode) {
194213
// Reset the memoizedState to what it was before we attempted
195214
// to render it.

0 commit comments

Comments
 (0)