Skip to content

Commit 9c9f1a3

Browse files
author
Brian Vaughn
committed
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.
1 parent 1add7e1 commit 9c9f1a3

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

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

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,6 @@ import {
120120
resolveRetryWakeable,
121121
markCommitTimeOfFallback,
122122
schedulePassiveEffectCallback,
123-
penultimateProfilerOnStack,
124123
} from './ReactFiberWorkLoop.new';
125124
import {
126125
NoFlags as NoHookEffect,
@@ -424,13 +423,6 @@ function commitProfilerPassiveEffect(
424423
);
425424
}
426425
}
427-
428-
// Bubble times to the next nearest ancestor Profiler.
429-
// After we process that Profiler, we'll bubble further up.
430-
if (penultimateProfilerOnStack !== null) {
431-
const stateNode = penultimateProfilerOnStack.stateNode;
432-
stateNode.passiveEffectDuration += passiveEffectDuration;
433-
}
434426
break;
435427
}
436428
default:
@@ -727,13 +719,6 @@ function commitLifeCycles(
727719
);
728720
}
729721
}
730-
731-
// Propagate layout effect durations to the next nearest Profiler ancestor.
732-
// Do not reset these values until the next render so DevTools has a chance to read them first.
733-
if (penultimateProfilerOnStack !== null) {
734-
const stateNode = penultimateProfilerOnStack.stateNode;
735-
stateNode.effectDuration += effectDuration;
736-
}
737722
}
738723
}
739724
return;

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ let shouldFireAfterActiveInstanceBlur: boolean = false;
370370

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

375374
export function getWorkInProgressRoot(): FiberRoot | null {
376375
return workInProgressRoot;
@@ -2367,11 +2366,10 @@ function commitLayoutEffects(
23672366
) {
23682367
let fiber = firstChild;
23692368
while (fiber !== null) {
2370-
let prevPenultimateProfiler = null;
2369+
let prevProfilerOnStack = null;
23712370
if (enableProfilerTimer && enableProfilerCommitHooks) {
23722371
if (fiber.tag === Profiler) {
2373-
prevPenultimateProfiler = penultimateProfilerOnStack;
2374-
penultimateProfilerOnStack = nearestProfilerOnStack;
2372+
prevProfilerOnStack = nearestProfilerOnStack;
23752373
nearestProfilerOnStack = fiber;
23762374
}
23772375
}
@@ -2408,8 +2406,13 @@ function commitLayoutEffects(
24082406

24092407
if (enableProfilerTimer && enableProfilerCommitHooks) {
24102408
if (fiber.tag === Profiler) {
2411-
nearestProfilerOnStack = penultimateProfilerOnStack;
2412-
penultimateProfilerOnStack = prevPenultimateProfiler;
2409+
// Propagate layout effect durations to the next nearest Profiler ancestor.
2410+
// Do not reset these values until the next render so DevTools has a chance to read them first.
2411+
if (prevProfilerOnStack !== null) {
2412+
prevProfilerOnStack.stateNode.effectDuration += fiber.stateNode.effectDuration;
2413+
}
2414+
2415+
nearestProfilerOnStack = prevProfilerOnStack;
24132416
}
24142417
}
24152418

@@ -2474,11 +2477,10 @@ export function flushPassiveEffects(): boolean {
24742477
function flushPassiveMountEffects(root, firstChild: Fiber): void {
24752478
let fiber = firstChild;
24762479
while (fiber !== null) {
2477-
let prevPenultimateProfiler = null;
2480+
let prevProfilerOnStack = null;
24782481
if (enableProfilerTimer && enableProfilerCommitHooks) {
24792482
if (fiber.tag === Profiler) {
2480-
prevPenultimateProfiler = penultimateProfilerOnStack;
2481-
penultimateProfilerOnStack = nearestProfilerOnStack;
2483+
prevProfilerOnStack = nearestProfilerOnStack;
24822484
nearestProfilerOnStack = fiber;
24832485
}
24842486
}
@@ -2515,8 +2517,13 @@ function flushPassiveMountEffects(root, firstChild: Fiber): void {
25152517

25162518
if (enableProfilerTimer && enableProfilerCommitHooks) {
25172519
if (fiber.tag === Profiler) {
2518-
nearestProfilerOnStack = penultimateProfilerOnStack;
2519-
penultimateProfilerOnStack = prevPenultimateProfiler;
2520+
// Bubble times to the next nearest ancestor Profiler.
2521+
// After we process that Profiler, we'll bubble further up.
2522+
if (prevProfilerOnStack !== null) {
2523+
prevProfilerOnStack.stateNode.passiveEffectDuration += fiber.stateNode.passiveEffectDuration;
2524+
}
2525+
2526+
nearestProfilerOnStack = prevProfilerOnStack;
25202527
}
25212528
}
25222529

0 commit comments

Comments
 (0)