Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved Profiler commit-phase bubbling into work loop
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 29, 2020
commit 17043993c5883ccba69ed69143abd48827261c27
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 @@ -121,7 +121,6 @@ import {
resolveRetryWakeable,
markCommitTimeOfFallback,
schedulePassiveEffectCallback,
penultimateProfilerOnStack,
} from './ReactFiberWorkLoop.new';
import {
NoFlags as NoHookEffect,
Expand Down Expand Up @@ -425,13 +424,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 @@ -728,13 +720,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
31 changes: 20 additions & 11 deletions packages/react-reconciler/src/ReactFiberWorkLoop.new.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,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 @@ -2368,11 +2367,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 @@ -2409,8 +2407,14 @@ 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 @@ -2475,11 +2479,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 @@ -2516,8 +2519,14 @@ 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