Skip to content

Commit

Permalink
Moved Profiler commit-phase bubbling into work loop
Browse files Browse the repository at this point in the history
This enables us to only track a single item in the stack and requires less ugly coupling between the work loop and commit work.
  • Loading branch information
Brian Vaughn committed Sep 23, 2020
1 parent 1add7e1 commit 9c9f1a3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
15 changes: 0 additions & 15 deletions packages/react-reconciler/src/ReactFiberCommitWork.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ import {
resolveRetryWakeable,
markCommitTimeOfFallback,
schedulePassiveEffectCallback,
penultimateProfilerOnStack,
} from './ReactFiberWorkLoop.new';
import {
NoFlags as NoHookEffect,
Expand Down Expand Up @@ -424,13 +423,6 @@ function commitProfilerPassiveEffect(
);
}
}

// Bubble times to the next nearest ancestor Profiler.
// After we process that Profiler, we'll bubble further up.
if (penultimateProfilerOnStack !== null) {
const stateNode = penultimateProfilerOnStack.stateNode;
stateNode.passiveEffectDuration += passiveEffectDuration;
}
break;
}
default:
Expand Down Expand Up @@ -727,13 +719,6 @@ function commitLifeCycles(
);
}
}

// Propagate layout effect durations to the next nearest Profiler ancestor.
// Do not reset these values until the next render so DevTools has a chance to read them first.
if (penultimateProfilerOnStack !== null) {
const stateNode = penultimateProfilerOnStack.stateNode;
stateNode.effectDuration += effectDuration;
}
}
}
return;
Expand Down
29 changes: 18 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ let shouldFireAfterActiveInstanceBlur: boolean = false;

// Used to avoid traversing the return path to find the nearest Profiler ancestor during commit.
let nearestProfilerOnStack: Fiber | null = null;
export let penultimateProfilerOnStack: Fiber | null = null;

export function getWorkInProgressRoot(): FiberRoot | null {
return workInProgressRoot;
Expand Down Expand Up @@ -2367,11 +2366,10 @@ function commitLayoutEffects(
) {
let fiber = firstChild;
while (fiber !== null) {
let prevPenultimateProfiler = null;
let prevProfilerOnStack = null;
if (enableProfilerTimer && enableProfilerCommitHooks) {
if (fiber.tag === Profiler) {
prevPenultimateProfiler = penultimateProfilerOnStack;
penultimateProfilerOnStack = nearestProfilerOnStack;
prevProfilerOnStack = nearestProfilerOnStack;
nearestProfilerOnStack = fiber;
}
}
Expand Down Expand Up @@ -2408,8 +2406,13 @@ function commitLayoutEffects(

if (enableProfilerTimer && enableProfilerCommitHooks) {
if (fiber.tag === Profiler) {
nearestProfilerOnStack = penultimateProfilerOnStack;
penultimateProfilerOnStack = prevPenultimateProfiler;
// Propagate layout effect durations to the next nearest Profiler ancestor.
// Do not reset these values until the next render so DevTools has a chance to read them first.
if (prevProfilerOnStack !== null) {
prevProfilerOnStack.stateNode.effectDuration += fiber.stateNode.effectDuration;
}

nearestProfilerOnStack = prevProfilerOnStack;
}
}

Expand Down Expand Up @@ -2474,11 +2477,10 @@ export function flushPassiveEffects(): boolean {
function flushPassiveMountEffects(root, firstChild: Fiber): void {
let fiber = firstChild;
while (fiber !== null) {
let prevPenultimateProfiler = null;
let prevProfilerOnStack = null;
if (enableProfilerTimer && enableProfilerCommitHooks) {
if (fiber.tag === Profiler) {
prevPenultimateProfiler = penultimateProfilerOnStack;
penultimateProfilerOnStack = nearestProfilerOnStack;
prevProfilerOnStack = nearestProfilerOnStack;
nearestProfilerOnStack = fiber;
}
}
Expand Down Expand Up @@ -2515,8 +2517,13 @@ function flushPassiveMountEffects(root, firstChild: Fiber): void {

if (enableProfilerTimer && enableProfilerCommitHooks) {
if (fiber.tag === Profiler) {
nearestProfilerOnStack = penultimateProfilerOnStack;
penultimateProfilerOnStack = prevPenultimateProfiler;
// Bubble times to the next nearest ancestor Profiler.
// After we process that Profiler, we'll bubble further up.
if (prevProfilerOnStack !== null) {
prevProfilerOnStack.stateNode.passiveEffectDuration += fiber.stateNode.passiveEffectDuration;
}

nearestProfilerOnStack = prevProfilerOnStack;
}
}

Expand Down

0 comments on commit 9c9f1a3

Please sign in to comment.