Skip to content

Commit 1c96252

Browse files
committed
Use executionContext to disable profiler timer
1 parent 509dec8 commit 1c96252

File tree

4 files changed

+43
-51
lines changed

4 files changed

+43
-51
lines changed

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

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ import {
147147
addMarkerProgressCallbackToPendingTransition,
148148
addMarkerCompleteCallbackToPendingTransition,
149149
setIsRunningInsertionEffect,
150+
getExecutionContext,
151+
CommitContext,
150152
} from './ReactFiberWorkLoop.new';
151153
import {
152154
NoFlags as NoHookEffect,
@@ -194,7 +196,6 @@ let nextEffect: Fiber | null = null;
194196
// Used for Profiling builds to track updaters.
195197
let inProgressLanes: Lanes | null = null;
196198
let inProgressRoot: FiberRoot | null = null;
197-
let enableProfilingDEV = true;
198199

199200
export function reportUncaughtErrorInDEV(error: mixed) {
200201
// Wrapping each small part of the commit phase into a guarded
@@ -217,7 +218,7 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
217218
enableProfilerTimer &&
218219
enableProfilerCommitHooks &&
219220
current.mode & ProfileMode &&
220-
enableProfilingDEV
221+
getExecutionContext() & CommitContext
221222
) {
222223
try {
223224
startLayoutEffectTimer();
@@ -262,7 +263,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
262263
enableProfilerTimer &&
263264
enableProfilerCommitHooks &&
264265
current.mode & ProfileMode &&
265-
enableProfilingDEV
266+
getExecutionContext() & CommitContext
266267
) {
267268
try {
268269
startLayoutEffectTimer();
@@ -639,7 +640,11 @@ export function commitPassiveEffectDurations(
639640
finishedRoot: FiberRoot,
640641
finishedWork: Fiber,
641642
): void {
642-
if (enableProfilerTimer && enableProfilerCommitHooks && enableProfilingDEV) {
643+
if (
644+
enableProfilerTimer &&
645+
enableProfilerCommitHooks &&
646+
getExecutionContext() & CommitContext
647+
) {
643648
// Only Profilers with work in their subtree will have an Update effect scheduled.
644649
if ((finishedWork.flags & Update) !== NoFlags) {
645650
switch (finishedWork.tag) {
@@ -696,7 +701,7 @@ function commitHookLayoutEffects(finishedWork: Fiber, hookFlags: HookFlags) {
696701
enableProfilerTimer &&
697702
enableProfilerCommitHooks &&
698703
finishedWork.mode & ProfileMode &&
699-
enableProfilingDEV
704+
getExecutionContext() & CommitContext
700705
) {
701706
try {
702707
startLayoutEffectTimer();
@@ -754,7 +759,7 @@ function commitClassLayoutLifecycles(
754759
enableProfilerTimer &&
755760
enableProfilerCommitHooks &&
756761
finishedWork.mode & ProfileMode &&
757-
enableProfilingDEV
762+
getExecutionContext() & CommitContext
758763
) {
759764
try {
760765
startLayoutEffectTimer();
@@ -810,7 +815,7 @@ function commitClassLayoutLifecycles(
810815
enableProfilerTimer &&
811816
enableProfilerCommitHooks &&
812817
finishedWork.mode & ProfileMode &&
813-
enableProfilingDEV
818+
getExecutionContext() & CommitContext
814819
) {
815820
try {
816821
startLayoutEffectTimer();
@@ -893,7 +898,7 @@ function commitHostComponentMount(finishedWork: Fiber) {
893898
}
894899

895900
function commitProfilerUpdate(finishedWork: Fiber, current: Fiber | null) {
896-
if (enableProfilerTimer && enableProfilingDEV) {
901+
if (enableProfilerTimer && getExecutionContext() & CommitContext) {
897902
try {
898903
const {onCommit, onRender} = finishedWork.memoizedProps;
899904
const {effectDuration} = finishedWork.stateNode;
@@ -1341,7 +1346,7 @@ function commitAttachRef(finishedWork: Fiber) {
13411346
enableProfilerTimer &&
13421347
enableProfilerCommitHooks &&
13431348
finishedWork.mode & ProfileMode &&
1344-
enableProfilingDEV
1349+
getExecutionContext() & CommitContext
13451350
) {
13461351
try {
13471352
startLayoutEffectTimer();
@@ -1385,7 +1390,7 @@ function commitDetachRef(current: Fiber) {
13851390
enableProfilerTimer &&
13861391
enableProfilerCommitHooks &&
13871392
current.mode & ProfileMode &&
1388-
enableProfilingDEV
1393+
getExecutionContext() & CommitContext
13891394
) {
13901395
try {
13911396
startLayoutEffectTimer();
@@ -1916,7 +1921,7 @@ function commitDeletionEffectsOnFiber(
19161921
enableProfilerTimer &&
19171922
enableProfilerCommitHooks &&
19181923
deletedFiber.mode & ProfileMode &&
1919-
enableProfilingDEV
1924+
getExecutionContext() & CommitContext
19201925
) {
19211926
startLayoutEffectTimer();
19221927
safelyCallDestroy(
@@ -2240,7 +2245,7 @@ function commitMutationEffectsOnFiber(
22402245
enableProfilerTimer &&
22412246
enableProfilerCommitHooks &&
22422247
finishedWork.mode & ProfileMode &&
2243-
enableProfilingDEV
2248+
getExecutionContext() & CommitContext
22442249
) {
22452250
try {
22462251
startLayoutEffectTimer();
@@ -2638,7 +2643,7 @@ export function disappearLayoutEffects(finishedWork: Fiber) {
26382643
enableProfilerTimer &&
26392644
enableProfilerCommitHooks &&
26402645
finishedWork.mode & ProfileMode &&
2641-
enableProfilingDEV
2646+
getExecutionContext() & CommitContext
26422647
) {
26432648
try {
26442649
startLayoutEffectTimer();
@@ -2891,7 +2896,7 @@ function commitHookPassiveMountEffects(
28912896
enableProfilerTimer &&
28922897
enableProfilerCommitHooks &&
28932898
finishedWork.mode & ProfileMode &&
2894-
enableProfilingDEV
2899+
getExecutionContext() & CommitContext
28952900
) {
28962901
startPassiveEffectTimer();
28972902
try {
@@ -3601,7 +3606,7 @@ function commitHookPassiveUnmountEffects(
36013606
enableProfilerTimer &&
36023607
enableProfilerCommitHooks &&
36033608
finishedWork.mode & ProfileMode &&
3604-
enableProfilingDEV
3609+
getExecutionContext() & CommitContext
36053610
) {
36063611
startPassiveEffectTimer();
36073612
commitHookEffectListUnmount(
@@ -3883,10 +3888,4 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
38833888
}
38843889
}
38853890

3886-
export function setEnableProfilingDEV(_enableProfilingDEV: boolean) {
3887-
if (__DEV__) {
3888-
enableProfilingDEV = _enableProfilingDEV;
3889-
}
3890-
}
3891-
38923891
export {commitPlacement, commitAttachRef, commitDetachRef};

packages/react-reconciler/src/ReactFiberCommitWork.old.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ import {
147147
addMarkerProgressCallbackToPendingTransition,
148148
addMarkerCompleteCallbackToPendingTransition,
149149
setIsRunningInsertionEffect,
150+
getExecutionContext,
151+
CommitContext,
150152
} from './ReactFiberWorkLoop.old';
151153
import {
152154
NoFlags as NoHookEffect,
@@ -194,7 +196,6 @@ let nextEffect: Fiber | null = null;
194196
// Used for Profiling builds to track updaters.
195197
let inProgressLanes: Lanes | null = null;
196198
let inProgressRoot: FiberRoot | null = null;
197-
let enableProfilingDEV = true;
198199

199200
export function reportUncaughtErrorInDEV(error: mixed) {
200201
// Wrapping each small part of the commit phase into a guarded
@@ -217,7 +218,7 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
217218
enableProfilerTimer &&
218219
enableProfilerCommitHooks &&
219220
current.mode & ProfileMode &&
220-
enableProfilingDEV
221+
getExecutionContext() & CommitContext
221222
) {
222223
try {
223224
startLayoutEffectTimer();
@@ -262,7 +263,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
262263
enableProfilerTimer &&
263264
enableProfilerCommitHooks &&
264265
current.mode & ProfileMode &&
265-
enableProfilingDEV
266+
getExecutionContext() & CommitContext
266267
) {
267268
try {
268269
startLayoutEffectTimer();
@@ -639,7 +640,11 @@ export function commitPassiveEffectDurations(
639640
finishedRoot: FiberRoot,
640641
finishedWork: Fiber,
641642
): void {
642-
if (enableProfilerTimer && enableProfilerCommitHooks && enableProfilingDEV) {
643+
if (
644+
enableProfilerTimer &&
645+
enableProfilerCommitHooks &&
646+
getExecutionContext() & CommitContext
647+
) {
643648
// Only Profilers with work in their subtree will have an Update effect scheduled.
644649
if ((finishedWork.flags & Update) !== NoFlags) {
645650
switch (finishedWork.tag) {
@@ -696,7 +701,7 @@ function commitHookLayoutEffects(finishedWork: Fiber, hookFlags: HookFlags) {
696701
enableProfilerTimer &&
697702
enableProfilerCommitHooks &&
698703
finishedWork.mode & ProfileMode &&
699-
enableProfilingDEV
704+
getExecutionContext() & CommitContext
700705
) {
701706
try {
702707
startLayoutEffectTimer();
@@ -754,7 +759,7 @@ function commitClassLayoutLifecycles(
754759
enableProfilerTimer &&
755760
enableProfilerCommitHooks &&
756761
finishedWork.mode & ProfileMode &&
757-
enableProfilingDEV
762+
getExecutionContext() & CommitContext
758763
) {
759764
try {
760765
startLayoutEffectTimer();
@@ -810,7 +815,7 @@ function commitClassLayoutLifecycles(
810815
enableProfilerTimer &&
811816
enableProfilerCommitHooks &&
812817
finishedWork.mode & ProfileMode &&
813-
enableProfilingDEV
818+
getExecutionContext() & CommitContext
814819
) {
815820
try {
816821
startLayoutEffectTimer();
@@ -893,7 +898,7 @@ function commitHostComponentMount(finishedWork: Fiber) {
893898
}
894899

895900
function commitProfilerUpdate(finishedWork: Fiber, current: Fiber | null) {
896-
if (enableProfilerTimer && enableProfilingDEV) {
901+
if (enableProfilerTimer && getExecutionContext() & CommitContext) {
897902
try {
898903
const {onCommit, onRender} = finishedWork.memoizedProps;
899904
const {effectDuration} = finishedWork.stateNode;
@@ -1341,7 +1346,7 @@ function commitAttachRef(finishedWork: Fiber) {
13411346
enableProfilerTimer &&
13421347
enableProfilerCommitHooks &&
13431348
finishedWork.mode & ProfileMode &&
1344-
enableProfilingDEV
1349+
getExecutionContext() & CommitContext
13451350
) {
13461351
try {
13471352
startLayoutEffectTimer();
@@ -1385,7 +1390,7 @@ function commitDetachRef(current: Fiber) {
13851390
enableProfilerTimer &&
13861391
enableProfilerCommitHooks &&
13871392
current.mode & ProfileMode &&
1388-
enableProfilingDEV
1393+
getExecutionContext() & CommitContext
13891394
) {
13901395
try {
13911396
startLayoutEffectTimer();
@@ -1916,7 +1921,7 @@ function commitDeletionEffectsOnFiber(
19161921
enableProfilerTimer &&
19171922
enableProfilerCommitHooks &&
19181923
deletedFiber.mode & ProfileMode &&
1919-
enableProfilingDEV
1924+
getExecutionContext() & CommitContext
19201925
) {
19211926
startLayoutEffectTimer();
19221927
safelyCallDestroy(
@@ -2240,7 +2245,7 @@ function commitMutationEffectsOnFiber(
22402245
enableProfilerTimer &&
22412246
enableProfilerCommitHooks &&
22422247
finishedWork.mode & ProfileMode &&
2243-
enableProfilingDEV
2248+
getExecutionContext() & CommitContext
22442249
) {
22452250
try {
22462251
startLayoutEffectTimer();
@@ -2638,7 +2643,7 @@ export function disappearLayoutEffects(finishedWork: Fiber) {
26382643
enableProfilerTimer &&
26392644
enableProfilerCommitHooks &&
26402645
finishedWork.mode & ProfileMode &&
2641-
enableProfilingDEV
2646+
getExecutionContext() & CommitContext
26422647
) {
26432648
try {
26442649
startLayoutEffectTimer();
@@ -2891,7 +2896,7 @@ function commitHookPassiveMountEffects(
28912896
enableProfilerTimer &&
28922897
enableProfilerCommitHooks &&
28932898
finishedWork.mode & ProfileMode &&
2894-
enableProfilingDEV
2899+
getExecutionContext() & CommitContext
28952900
) {
28962901
startPassiveEffectTimer();
28972902
try {
@@ -3601,7 +3606,7 @@ function commitHookPassiveUnmountEffects(
36013606
enableProfilerTimer &&
36023607
enableProfilerCommitHooks &&
36033608
finishedWork.mode & ProfileMode &&
3604-
enableProfilingDEV
3609+
getExecutionContext() & CommitContext
36053610
) {
36063611
startPassiveEffectTimer();
36073612
commitHookEffectListUnmount(
@@ -3883,10 +3888,4 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
38833888
}
38843889
}
38853890

3886-
export function setEnableProfilingDEV(_enableProfilingDEV: boolean) {
3887-
if (__DEV__) {
3888-
enableProfilingDEV = _enableProfilingDEV;
3889-
}
3890-
}
3891-
38923891
export {commitPlacement, commitAttachRef, commitDetachRef};

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ import {
186186
reappearLayoutEffects,
187187
disconnectPassiveEffect,
188188
reportUncaughtErrorInDEV,
189-
setEnableProfilingDEV,
190189
} from './ReactFiberCommitWork.new';
191190
import {enqueueUpdate} from './ReactFiberClassUpdateQueue.new';
192191
import {resetContextDependencies} from './ReactFiberNewContext.new';
@@ -267,7 +266,7 @@ type ExecutionContext = number;
267266
export const NoContext = /* */ 0b000;
268267
const BatchedContext = /* */ 0b001;
269268
const RenderContext = /* */ 0b010;
270-
const CommitContext = /* */ 0b100;
269+
export const CommitContext = /* */ 0b100;
271270

272271
type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5 | 6;
273272
const RootInProgress = 0;
@@ -2963,14 +2962,12 @@ function commitDoubleInvokeEffectsInDEV(
29632962
) {
29642963
doubleInvokeEffects = false;
29652964
}
2966-
setEnableProfilingDEV(false);
29672965
recursivelyTraverseAndDoubleInvokeEffectsInDEV(
29682966
root,
29692967
root.current,
29702968
hasPassiveEffects,
29712969
doubleInvokeEffects,
29722970
);
2973-
setEnableProfilingDEV(true);
29742971
}
29752972
}
29762973

packages/react-reconciler/src/ReactFiberWorkLoop.old.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type {Wakeable} from 'shared/ReactTypes';
1313
import type {Fiber, FiberRoot} from './ReactInternalTypes';
1414
import type {Lanes, Lane} from './ReactFiberLane.old';
1515
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
16-
import {PlacementDEV} from './ReactFiberFlags';
1716
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old';
1817
import type {EventPriority} from './ReactEventPriorities.old';
1918
import type {
@@ -122,6 +121,7 @@ import {
122121
MutationMask,
123122
LayoutMask,
124123
PassiveMask,
124+
PlacementDEV,
125125
} from './ReactFiberFlags';
126126
import {
127127
NoLanes,
@@ -186,7 +186,6 @@ import {
186186
reappearLayoutEffects,
187187
disconnectPassiveEffect,
188188
reportUncaughtErrorInDEV,
189-
setEnableProfilingDEV,
190189
} from './ReactFiberCommitWork.old';
191190
import {enqueueUpdate} from './ReactFiberClassUpdateQueue.old';
192191
import {resetContextDependencies} from './ReactFiberNewContext.old';
@@ -267,7 +266,7 @@ type ExecutionContext = number;
267266
export const NoContext = /* */ 0b000;
268267
const BatchedContext = /* */ 0b001;
269268
const RenderContext = /* */ 0b010;
270-
const CommitContext = /* */ 0b100;
269+
export const CommitContext = /* */ 0b100;
271270

272271
type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5 | 6;
273272
const RootInProgress = 0;
@@ -2963,14 +2962,12 @@ function commitDoubleInvokeEffectsInDEV(
29632962
) {
29642963
doubleInvokeEffects = false;
29652964
}
2966-
setEnableProfilingDEV(false);
29672965
recursivelyTraverseAndDoubleInvokeEffectsInDEV(
29682966
root,
29692967
root.current,
29702968
hasPassiveEffects,
29712969
doubleInvokeEffects,
29722970
);
2973-
setEnableProfilingDEV(true);
29742971
}
29752972
}
29762973

0 commit comments

Comments
 (0)