Skip to content

Commit 7642d82

Browse files
author
Brian Vaughn
committed
Store commit durations on HostRoot for DevTools access
1 parent bd245c1 commit 7642d82

File tree

2 files changed

+60
-32
lines changed

2 files changed

+60
-32
lines changed

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

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
enableProfilerNestedUpdatePhase,
1515
enableProfilerTimer,
1616
} from 'shared/ReactFeatureFlags';
17-
import {Profiler} from './ReactWorkTags';
17+
import {HostRoot, Profiler} from './ReactWorkTags';
1818

1919
// Intentionally not named imports because Rollup would use dynamic dispatch for
2020
// CommonJS interop named imports.
@@ -140,13 +140,19 @@ function recordLayoutEffectDuration(fiber: Fiber): void {
140140

141141
layoutEffectStartTime = -1;
142142

143-
// Store duration on the next nearest Profiler ancestor.
143+
// Store duration on the next nearest Profiler ancestor
144+
// Or the root (for the DevTools Profiler to read)
144145
let parentFiber = fiber.return;
145146
while (parentFiber !== null) {
146-
if (parentFiber.tag === Profiler) {
147-
const parentStateNode = parentFiber.stateNode;
148-
parentStateNode.effectDuration += elapsedTime;
149-
break;
147+
switch (parentFiber.tag) {
148+
case HostRoot:
149+
const root = parentFiber.stateNode;
150+
root.effectDuration += elapsedTime;
151+
return;
152+
case Profiler:
153+
const parentStateNode = parentFiber.stateNode;
154+
parentStateNode.effectDuration += elapsedTime;
155+
return;
150156
}
151157
parentFiber = parentFiber.return;
152158
}
@@ -163,18 +169,26 @@ function recordPassiveEffectDuration(fiber: Fiber): void {
163169

164170
passiveEffectStartTime = -1;
165171

166-
// Store duration on the next nearest Profiler ancestor.
172+
// Store duration on the next nearest Profiler ancestor
173+
// Or the root (for the DevTools Profiler to read)
167174
let parentFiber = fiber.return;
168175
while (parentFiber !== null) {
169-
if (parentFiber.tag === Profiler) {
170-
const parentStateNode = parentFiber.stateNode;
171-
if (parentStateNode !== null) {
172-
// Detached fibers have their state node cleared out.
173-
// In this case, the return pointer is also cleared out,
174-
// so we won't be able to report the time spent in this Profiler's subtree.
175-
parentStateNode.passiveEffectDuration += elapsedTime;
176-
}
177-
break;
176+
switch (parentFiber.tag) {
177+
case HostRoot:
178+
const root = parentFiber.stateNode;
179+
if (root !== null) {
180+
root.passiveEffectDuration += elapsedTime;
181+
}
182+
return;
183+
case Profiler:
184+
const parentStateNode = parentFiber.stateNode;
185+
if (parentStateNode !== null) {
186+
// Detached fibers have their state node cleared out.
187+
// In this case, the return pointer is also cleared out,
188+
// so we won't be able to report the time spent in this Profiler's subtree.
189+
parentStateNode.passiveEffectDuration += elapsedTime;
190+
}
191+
return;
178192
}
179193
parentFiber = parentFiber.return;
180194
}

packages/react-reconciler/src/ReactProfilerTimer.old.js

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
enableProfilerNestedUpdatePhase,
1515
enableProfilerTimer,
1616
} from 'shared/ReactFeatureFlags';
17-
import {Profiler} from './ReactWorkTags';
17+
import {HostRoot, Profiler} from './ReactWorkTags';
1818

1919
// Intentionally not named imports because Rollup would use dynamic dispatch for
2020
// CommonJS interop named imports.
@@ -140,13 +140,19 @@ function recordLayoutEffectDuration(fiber: Fiber): void {
140140

141141
layoutEffectStartTime = -1;
142142

143-
// Store duration on the next nearest Profiler ancestor.
143+
// Store duration on the next nearest Profiler ancestor
144+
// Or the root (for the DevTools Profiler to read)
144145
let parentFiber = fiber.return;
145146
while (parentFiber !== null) {
146-
if (parentFiber.tag === Profiler) {
147-
const parentStateNode = parentFiber.stateNode;
148-
parentStateNode.effectDuration += elapsedTime;
149-
break;
147+
switch (parentFiber.tag) {
148+
case HostRoot:
149+
const root = parentFiber.stateNode;
150+
root.effectDuration += elapsedTime;
151+
return;
152+
case Profiler:
153+
const parentStateNode = parentFiber.stateNode;
154+
parentStateNode.effectDuration += elapsedTime;
155+
return;
150156
}
151157
parentFiber = parentFiber.return;
152158
}
@@ -163,18 +169,26 @@ function recordPassiveEffectDuration(fiber: Fiber): void {
163169

164170
passiveEffectStartTime = -1;
165171

166-
// Store duration on the next nearest Profiler ancestor.
172+
// Store duration on the next nearest Profiler ancestor
173+
// Or the root (for the DevTools Profiler to read)
167174
let parentFiber = fiber.return;
168175
while (parentFiber !== null) {
169-
if (parentFiber.tag === Profiler) {
170-
const parentStateNode = parentFiber.stateNode;
171-
if (parentStateNode !== null) {
172-
// Detached fibers have their state node cleared out.
173-
// In this case, the return pointer is also cleared out,
174-
// so we won't be able to report the time spent in this Profiler's subtree.
175-
parentStateNode.passiveEffectDuration += elapsedTime;
176-
}
177-
break;
176+
switch (parentFiber.tag) {
177+
case HostRoot:
178+
const root = parentFiber.stateNode;
179+
if (root !== null) {
180+
root.passiveEffectDuration += elapsedTime;
181+
}
182+
return;
183+
case Profiler:
184+
const parentStateNode = parentFiber.stateNode;
185+
if (parentStateNode !== null) {
186+
// Detached fibers have their state node cleared out.
187+
// In this case, the return pointer is also cleared out,
188+
// so we won't be able to report the time spent in this Profiler's subtree.
189+
parentStateNode.passiveEffectDuration += elapsedTime;
190+
}
191+
return;
178192
}
179193
parentFiber = parentFiber.return;
180194
}

0 commit comments

Comments
 (0)