Skip to content

Commit 3c244db

Browse files
author
Brian Vaughn
committed
Renamed selfBaseTime/treeBaseTime Fiber attributes to selfBaseDuration/treeBaseDuration
This is an unobservable change to all but the (under development) DevTools Profiler plugin. It is being done so that the plugin can safely feature detect a version of React that supports it. The profiler API has existed since the 16.4.0 release, but it did not support the DevTools plugin prior to PR facebook#13058. Side note: I am not a big fan of the term "base duration". Both it and "actual duration" are kind of awkward and vague. If anyone has suggestions for better names– this is the best time to bikeshed about them.
1 parent 1386ccd commit 3c244db

File tree

5 files changed

+22
-18
lines changed

5 files changed

+22
-18
lines changed

packages/react-reconciler/src/ReactFiber.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,12 @@ export type Fiber = {|
166166
// Duration of the most recent render time for this Fiber.
167167
// This value is not updated when we bailout for memoization purposes.
168168
// This field is only set when the enableProfilerTimer flag is enabled.
169-
selfBaseTime?: number,
169+
selfBaseDuration?: number,
170170

171171
// Sum of base times for all descedents of this Fiber.
172172
// This value bubbles up during the "complete" phase.
173173
// This field is only set when the enableProfilerTimer flag is enabled.
174-
treeBaseTime?: number,
174+
treeBaseDuration?: number,
175175

176176
// Conceptual aliases
177177
// workInProgress : Fiber -> alternate The alternate used for reuse happens
@@ -230,8 +230,8 @@ function FiberNode(
230230
if (enableProfilerTimer) {
231231
this.actualDuration = 0;
232232
this.actualStartTime = 0;
233-
this.selfBaseTime = 0;
234-
this.treeBaseTime = 0;
233+
this.selfBaseDuration = 0;
234+
this.treeBaseDuration = 0;
235235
}
236236

237237
if (__DEV__) {
@@ -338,8 +338,8 @@ export function createWorkInProgress(
338338
workInProgress.ref = current.ref;
339339

340340
if (enableProfilerTimer) {
341-
workInProgress.selfBaseTime = current.selfBaseTime;
342-
workInProgress.treeBaseTime = current.treeBaseTime;
341+
workInProgress.selfBaseDuration = current.selfBaseDuration;
342+
workInProgress.treeBaseDuration = current.treeBaseDuration;
343343
}
344344

345345
return workInProgress;
@@ -569,8 +569,8 @@ export function assignFiberPropertiesInDEV(
569569
if (enableProfilerTimer) {
570570
target.actualDuration = source.actualDuration;
571571
target.actualStartTime = source.actualStartTime;
572-
target.selfBaseTime = source.selfBaseTime;
573-
target.treeBaseTime = source.treeBaseTime;
572+
target.selfBaseDuration = source.selfBaseDuration;
573+
target.treeBaseDuration = source.treeBaseDuration;
574574
}
575575
target._debugID = source._debugID;
576576
target._debugSource = source._debugSource;

packages/react-reconciler/src/ReactFiberCommitWork.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
830830
finishedWork.memoizedProps.id,
831831
current === null ? 'mount' : 'update',
832832
finishedWork.actualDuration,
833-
finishedWork.treeBaseTime,
833+
finishedWork.treeBaseDuration,
834834
finishedWork.actualStartTime,
835835
getCommitTime(),
836836
);

packages/react-reconciler/src/ReactFiberScheduler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -736,10 +736,10 @@ function resetExpirationTime(
736736
// Bubble up the earliest expiration time.
737737
// (And "base" render timers if that feature flag is enabled)
738738
if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
739-
let treeBaseTime = workInProgress.selfBaseTime;
739+
let treeBaseDuration = workInProgress.selfBaseDuration;
740740
let child = workInProgress.child;
741741
while (child !== null) {
742-
treeBaseTime += child.treeBaseTime;
742+
treeBaseDuration += child.treeBaseDuration;
743743
if (
744744
child.expirationTime !== NoWork &&
745745
(newExpirationTime === NoWork ||
@@ -749,7 +749,7 @@ function resetExpirationTime(
749749
}
750750
child = child.sibling;
751751
}
752-
workInProgress.treeBaseTime = treeBaseTime;
752+
workInProgress.treeBaseDuration = treeBaseDuration;
753753
} else {
754754
let child = workInProgress.child;
755755
while (child !== null) {

packages/react-reconciler/src/ReactProfilerTimer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ function recordElapsedBaseRenderTimeIfRunning(fiber: Fiber): void {
153153
return;
154154
}
155155
if (baseStartTime !== -1) {
156-
fiber.selfBaseTime = now() - baseStartTime;
156+
fiber.selfBaseDuration = now() - baseStartTime;
157157
}
158158
}
159159

packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ describe('ReactProfiler DevTools integration', () => {
9292
// At this point, the base time should include both:
9393
// The time 2ms in the App component itself, and
9494
// The 10ms spend in the Profiler sub-tree beneath.
95-
expect(rendered.root.findByType(App)._currentFiber().treeBaseTime).toBe(12);
95+
expect(rendered.root.findByType(App)._currentFiber().treeBaseDuration).toBe(
96+
12,
97+
);
9698

9799
rendered.update(<App multiplier={2} />);
98100

@@ -106,7 +108,9 @@ describe('ReactProfiler DevTools integration', () => {
106108
// At this point, the base time should include both:
107109
// The initial 9ms for the components that do not re-render, and
108110
// The updated 6ms for the component that does.
109-
expect(rendered.root.findByType(App)._currentFiber().treeBaseTime).toBe(15);
111+
expect(rendered.root.findByType(App)._currentFiber().treeBaseDuration).toBe(
112+
15,
113+
);
110114
});
111115

112116
it('should reset the fiber stack correctly after an error when profiling host roots', () => {
@@ -141,8 +145,8 @@ describe('ReactProfiler DevTools integration', () => {
141145
// At this point, the base time should include only the most recent (not failed) render.
142146
// It should not include time spent on the initial render,
143147
// Or time that elapsed between any of the above renders.
144-
expect(rendered.root.findByType('div')._currentFiber().treeBaseTime).toBe(
145-
7,
146-
);
148+
expect(
149+
rendered.root.findByType('div')._currentFiber().treeBaseDuration,
150+
).toBe(7);
147151
});
148152
});

0 commit comments

Comments
 (0)