Skip to content
Merged
Prev Previous commit
Next Next commit
Use executionContext to disable profiler timer
  • Loading branch information
sammy-SC committed Aug 12, 2022
commit f1579c2af9ca73886efa7eec2340c9dab0fffc22
41 changes: 20 additions & 21 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ import {
addMarkerProgressCallbackToPendingTransition,
addMarkerCompleteCallbackToPendingTransition,
setIsRunningInsertionEffect,
getExecutionContext,
CommitContext,
} from './ReactFiberWorkLoop.new';
import {
NoFlags as NoHookEffect,
Expand Down Expand Up @@ -198,7 +200,6 @@ let nextEffect: Fiber | null = null;
// Used for Profiling builds to track updaters.
let inProgressLanes: Lanes | null = null;
let inProgressRoot: FiberRoot | null = null;
let enableProfilingDEV = true;

export function reportUncaughtErrorInDEV(error: mixed) {
// Wrapping each small part of the commit phase into a guarded
Expand All @@ -221,7 +222,7 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
current.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -266,7 +267,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
current.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -643,7 +644,11 @@ export function commitPassiveEffectDurations(
finishedRoot: FiberRoot,
finishedWork: Fiber,
): void {
if (enableProfilerTimer && enableProfilerCommitHooks && enableProfilingDEV) {
if (
enableProfilerTimer &&
enableProfilerCommitHooks &&
getExecutionContext() & CommitContext
) {
// Only Profilers with work in their subtree will have an Update effect scheduled.
if ((finishedWork.flags & Update) !== NoFlags) {
switch (finishedWork.tag) {
Expand Down Expand Up @@ -700,7 +705,7 @@ function commitHookLayoutEffects(finishedWork: Fiber, hookFlags: HookFlags) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -758,7 +763,7 @@ function commitClassLayoutLifecycles(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -814,7 +819,7 @@ function commitClassLayoutLifecycles(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -897,7 +902,7 @@ function commitHostComponentMount(finishedWork: Fiber) {
}

function commitProfilerUpdate(finishedWork: Fiber, current: Fiber | null) {
if (enableProfilerTimer && enableProfilingDEV) {
if (enableProfilerTimer && getExecutionContext() & CommitContext) {
try {
const {onCommit, onRender} = finishedWork.memoizedProps;
const {effectDuration} = finishedWork.stateNode;
Expand Down Expand Up @@ -1350,7 +1355,7 @@ function commitAttachRef(finishedWork: Fiber) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -1394,7 +1399,7 @@ function commitDetachRef(current: Fiber) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
current.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -1925,7 +1930,7 @@ function commitDeletionEffectsOnFiber(
enableProfilerTimer &&
enableProfilerCommitHooks &&
deletedFiber.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
startLayoutEffectTimer();
safelyCallDestroy(
Expand Down Expand Up @@ -2249,7 +2254,7 @@ function commitMutationEffectsOnFiber(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -2647,7 +2652,7 @@ export function disappearLayoutEffects(finishedWork: Fiber) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -2890,7 +2895,7 @@ function commitHookPassiveMountEffects(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
startPassiveEffectTimer();
try {
Expand Down Expand Up @@ -3600,7 +3605,7 @@ function commitHookPassiveUnmountEffects(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
startPassiveEffectTimer();
commitHookEffectListUnmount(
Expand Down Expand Up @@ -3882,10 +3887,4 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
}
}

export function setEnableProfilingDEV(_enableProfilingDEV: boolean) {
if (__DEV__) {
enableProfilingDEV = _enableProfilingDEV;
}
}

export {commitPlacement, commitAttachRef, commitDetachRef};
41 changes: 20 additions & 21 deletions packages/react-reconciler/src/ReactFiberCommitWork.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ import {
addMarkerProgressCallbackToPendingTransition,
addMarkerCompleteCallbackToPendingTransition,
setIsRunningInsertionEffect,
getExecutionContext,
CommitContext,
} from './ReactFiberWorkLoop.old';
import {
NoFlags as NoHookEffect,
Expand Down Expand Up @@ -198,7 +200,6 @@ let nextEffect: Fiber | null = null;
// Used for Profiling builds to track updaters.
let inProgressLanes: Lanes | null = null;
let inProgressRoot: FiberRoot | null = null;
let enableProfilingDEV = true;

export function reportUncaughtErrorInDEV(error: mixed) {
// Wrapping each small part of the commit phase into a guarded
Expand All @@ -221,7 +222,7 @@ const callComponentWillUnmountWithTimer = function(current, instance) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
current.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -266,7 +267,7 @@ function safelyDetachRef(current: Fiber, nearestMountedAncestor: Fiber | null) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
current.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -643,7 +644,11 @@ export function commitPassiveEffectDurations(
finishedRoot: FiberRoot,
finishedWork: Fiber,
): void {
if (enableProfilerTimer && enableProfilerCommitHooks && enableProfilingDEV) {
if (
enableProfilerTimer &&
enableProfilerCommitHooks &&
getExecutionContext() & CommitContext
) {
// Only Profilers with work in their subtree will have an Update effect scheduled.
if ((finishedWork.flags & Update) !== NoFlags) {
switch (finishedWork.tag) {
Expand Down Expand Up @@ -700,7 +705,7 @@ function commitHookLayoutEffects(finishedWork: Fiber, hookFlags: HookFlags) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -758,7 +763,7 @@ function commitClassLayoutLifecycles(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -814,7 +819,7 @@ function commitClassLayoutLifecycles(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -897,7 +902,7 @@ function commitHostComponentMount(finishedWork: Fiber) {
}

function commitProfilerUpdate(finishedWork: Fiber, current: Fiber | null) {
if (enableProfilerTimer && enableProfilingDEV) {
if (enableProfilerTimer && getExecutionContext() & CommitContext) {
try {
const {onCommit, onRender} = finishedWork.memoizedProps;
const {effectDuration} = finishedWork.stateNode;
Expand Down Expand Up @@ -1350,7 +1355,7 @@ function commitAttachRef(finishedWork: Fiber) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -1394,7 +1399,7 @@ function commitDetachRef(current: Fiber) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
current.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -1925,7 +1930,7 @@ function commitDeletionEffectsOnFiber(
enableProfilerTimer &&
enableProfilerCommitHooks &&
deletedFiber.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
startLayoutEffectTimer();
safelyCallDestroy(
Expand Down Expand Up @@ -2249,7 +2254,7 @@ function commitMutationEffectsOnFiber(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -2647,7 +2652,7 @@ export function disappearLayoutEffects(finishedWork: Fiber) {
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
try {
startLayoutEffectTimer();
Expand Down Expand Up @@ -2890,7 +2895,7 @@ function commitHookPassiveMountEffects(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
startPassiveEffectTimer();
try {
Expand Down Expand Up @@ -3600,7 +3605,7 @@ function commitHookPassiveUnmountEffects(
enableProfilerTimer &&
enableProfilerCommitHooks &&
finishedWork.mode & ProfileMode &&
enableProfilingDEV
getExecutionContext() & CommitContext
) {
startPassiveEffectTimer();
commitHookEffectListUnmount(
Expand Down Expand Up @@ -3882,10 +3887,4 @@ function commitPassiveUnmountInsideDeletedTreeOnFiber(
}
}

export function setEnableProfilingDEV(_enableProfilingDEV: boolean) {
if (__DEV__) {
enableProfilingDEV = _enableProfilingDEV;
}
}

export {commitPlacement, commitAttachRef, commitDetachRef};
5 changes: 1 addition & 4 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ import {
reappearLayoutEffects,
disconnectPassiveEffect,
reportUncaughtErrorInDEV,
setEnableProfilingDEV,
} from './ReactFiberCommitWork.new';
import {enqueueUpdate} from './ReactFiberClassUpdateQueue.new';
import {resetContextDependencies} from './ReactFiberNewContext.new';
Expand Down Expand Up @@ -274,7 +273,7 @@ type ExecutionContext = number;
export const NoContext = /* */ 0b000;
const BatchedContext = /* */ 0b001;
const RenderContext = /* */ 0b010;
const CommitContext = /* */ 0b100;
export const CommitContext = /* */ 0b100;

type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5 | 6;
const RootInProgress = 0;
Expand Down Expand Up @@ -3058,14 +3057,12 @@ function commitDoubleInvokeEffectsInDEV(
) {
doubleInvokeEffects = false;
}
setEnableProfilingDEV(false);
recursivelyTraverseAndDoubleInvokeEffectsInDEV(
root,
root.current,
hasPassiveEffects,
doubleInvokeEffects,
);
setEnableProfilingDEV(true);
}
}

Expand Down
7 changes: 2 additions & 5 deletions packages/react-reconciler/src/ReactFiberWorkLoop.old.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {Wakeable} from 'shared/ReactTypes';
import type {Fiber, FiberRoot} from './ReactInternalTypes';
import type {Lanes, Lane} from './ReactFiberLane.old';
import type {SuspenseState} from './ReactFiberSuspenseComponent.old';
import {PlacementDEV} from './ReactFiberFlags';
import type {FunctionComponentUpdateQueue} from './ReactFiberHooks.old';
import type {EventPriority} from './ReactEventPriorities.old';
import type {
Expand Down Expand Up @@ -123,6 +122,7 @@ import {
MutationMask,
LayoutMask,
PassiveMask,
PlacementDEV,
} from './ReactFiberFlags';
import {
NoLanes,
Expand Down Expand Up @@ -187,7 +187,6 @@ import {
reappearLayoutEffects,
disconnectPassiveEffect,
reportUncaughtErrorInDEV,
setEnableProfilingDEV,
} from './ReactFiberCommitWork.old';
import {enqueueUpdate} from './ReactFiberClassUpdateQueue.old';
import {resetContextDependencies} from './ReactFiberNewContext.old';
Expand Down Expand Up @@ -274,7 +273,7 @@ type ExecutionContext = number;
export const NoContext = /* */ 0b000;
const BatchedContext = /* */ 0b001;
const RenderContext = /* */ 0b010;
const CommitContext = /* */ 0b100;
export const CommitContext = /* */ 0b100;

type RootExitStatus = 0 | 1 | 2 | 3 | 4 | 5 | 6;
const RootInProgress = 0;
Expand Down Expand Up @@ -3058,14 +3057,12 @@ function commitDoubleInvokeEffectsInDEV(
) {
doubleInvokeEffects = false;
}
setEnableProfilingDEV(false);
recursivelyTraverseAndDoubleInvokeEffectsInDEV(
root,
root.current,
hasPassiveEffects,
doubleInvokeEffects,
);
setEnableProfilingDEV(true);
}
}

Expand Down