From 9c9f1a32954a310b0fe2ffda78545d59a2c56bbe Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 23 Sep 2020 15:32:05 -0400 Subject: [PATCH] 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. --- .../src/ReactFiberCommitWork.new.js | 15 ---------- .../src/ReactFiberWorkLoop.new.js | 29 ++++++++++++------- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.new.js b/packages/react-reconciler/src/ReactFiberCommitWork.new.js index 615ea8ac3edf3..2079e464d34eb 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.new.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.new.js @@ -120,7 +120,6 @@ import { resolveRetryWakeable, markCommitTimeOfFallback, schedulePassiveEffectCallback, - penultimateProfilerOnStack, } from './ReactFiberWorkLoop.new'; import { NoFlags as NoHookEffect, @@ -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: @@ -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; diff --git a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js index 1d3ccfecabb28..039d87e81a4e7 100644 --- a/packages/react-reconciler/src/ReactFiberWorkLoop.new.js +++ b/packages/react-reconciler/src/ReactFiberWorkLoop.new.js @@ -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; @@ -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; } } @@ -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; } } @@ -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; } } @@ -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; } }