@samitouri / QOS-React / commits / 6f6b560a64

Renamed selfBaseTime/treeBaseTime Fiber attributes to selfBaseDuration/treeBaseDuration (#13156)

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 #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.

Brian Vaughn committed Jul 6, 2018 at 08:25 UTC 6f6b560a645adb595ba1e40630a3915d8abdf038
5 files changed +22 -18
packages/react-reconciler/src/ReactFiber.js
+8 -8
@@ -166,12 +166,12 @@ export type Fiber = {|
166 // Duration of the most recent render time for this Fiber.
167 // This value is not updated when we bailout for memoization purposes.
168 // This field is only set when the enableProfilerTimer flag is enabled.
169 - selfBaseTime?: number,
169 + selfBaseDuration?: number,
170
171 // Sum of base times for all descedents of this Fiber.
172 // This value bubbles up during the "complete" phase.
173 // This field is only set when the enableProfilerTimer flag is enabled.
174 - treeBaseTime?: number,
174 + treeBaseDuration?: number,
175
176 // Conceptual aliases
177 // workInProgress : Fiber -> alternate The alternate used for reuse happens
@@ -230,8 +230,8 @@ function FiberNode(
230 if (enableProfilerTimer) {
231 this.actualDuration = 0;
232 this.actualStartTime = 0;
233 - this.selfBaseTime = 0;
234 - this.treeBaseTime = 0;
233 + this.selfBaseDuration = 0;
234 + this.treeBaseDuration = 0;
235 }
236
237 if (__DEV__) {
@@ -338,8 +338,8 @@ export function createWorkInProgress(
338 workInProgress.ref = current.ref;
339
340 if (enableProfilerTimer) {
341 - workInProgress.selfBaseTime = current.selfBaseTime;
342 - workInProgress.treeBaseTime = current.treeBaseTime;
341 + workInProgress.selfBaseDuration = current.selfBaseDuration;
342 + workInProgress.treeBaseDuration = current.treeBaseDuration;
343 }
344
345 return workInProgress;
@@ -569,8 +569,8 @@ export function assignFiberPropertiesInDEV(
569 if (enableProfilerTimer) {
570 target.actualDuration = source.actualDuration;
571 target.actualStartTime = source.actualStartTime;
572 - target.selfBaseTime = source.selfBaseTime;
573 - target.treeBaseTime = source.treeBaseTime;
572 + target.selfBaseDuration = source.selfBaseDuration;
573 + target.treeBaseDuration = source.treeBaseDuration;
574 }
575 target._debugID = source._debugID;
576 target._debugSource = source._debugSource;
packages/react-reconciler/src/ReactFiberCommitWork.js
+1 -1
@@ -830,7 +830,7 @@ function commitWork(current: Fiber | null, finishedWork: Fiber): void {
830 finishedWork.memoizedProps.id,
831 current === null ? 'mount' : 'update',
832 finishedWork.actualDuration,
833 - finishedWork.treeBaseTime,
833 + finishedWork.treeBaseDuration,
834 finishedWork.actualStartTime,
835 getCommitTime(),
836 );
packages/react-reconciler/src/ReactFiberScheduler.js
+3 -3
@@ -736,10 +736,10 @@ function resetExpirationTime(
736 // Bubble up the earliest expiration time.
737 // (And "base" render timers if that feature flag is enabled)
738 if (enableProfilerTimer && workInProgress.mode & ProfileMode) {
739 - let treeBaseTime = workInProgress.selfBaseTime;
739 + let treeBaseDuration = workInProgress.selfBaseDuration;
740 let child = workInProgress.child;
741 while (child !== null) {
742 - treeBaseTime += child.treeBaseTime;
742 + treeBaseDuration += child.treeBaseDuration;
743 if (
744 child.expirationTime !== NoWork &&
745 (newExpirationTime === NoWork ||
@@ -749,7 +749,7 @@ function resetExpirationTime(
749 }
750 child = child.sibling;
751 }
752 - workInProgress.treeBaseTime = treeBaseTime;
752 + workInProgress.treeBaseDuration = treeBaseDuration;
753 } else {
754 let child = workInProgress.child;
755 while (child !== null) {
packages/react-reconciler/src/ReactProfilerTimer.js
+1 -1
@@ -153,7 +153,7 @@ function recordElapsedBaseRenderTimeIfRunning(fiber: Fiber): void {
153 return;
154 }
155 if (baseStartTime !== -1) {
156 - fiber.selfBaseTime = now() - baseStartTime;
156 + fiber.selfBaseDuration = now() - baseStartTime;
157 }
158 }
159
packages/react/src/__tests__/ReactProfilerDevToolsIntegration-test.internal.js
+9 -5
@@ -92,7 +92,9 @@ describe('ReactProfiler DevTools integration', () => {
92 // At this point, the base time should include both:
93 // The time 2ms in the App component itself, and
94 // 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 + );
98
99 rendered.update(<App multiplier={2} />);
100
@@ -106,7 +108,9 @@ describe('ReactProfiler DevTools integration', () => {
108 // At this point, the base time should include both:
109 // The initial 9ms for the components that do not re-render, and
110 // 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 + );
114 });
115
116 it('should reset the fiber stack correctly after an error when profiling host roots', () => {
@@ -141,8 +145,8 @@ describe('ReactProfiler DevTools integration', () => {
145 // At this point, the base time should include only the most recent (not failed) render.
146 // It should not include time spent on the initial render,
147 // 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);
151 });
152 });