Skip to content

Commit 94e4aca

Browse files
authored
[Fiber] Set profiler values to doubles (#30942)
At some point this trick was added to initialize the value first to NaN and then replace them with zeros and negative ones. This is to address the issue noted in #14365 where these hidden classes can be initialized to SMIs at first and then deopt when we realize they're actually doubles. However, this fix has been long broken and has deopted the profiling build for years because closure compiler optimizes out the first write. I'm not sure because I haven't A/B-tested this in the JIT yet but I think we can use negative zero and -1.1 as the initial values instead since they're not simple integers. Negative zero `===` zero (but not Object.is) so is the same as far as our code is concerned. The negative value is just `< 0` comparisons.
1 parent 206df66 commit 94e4aca

File tree

2 files changed

+17
-24
lines changed

2 files changed

+17
-24
lines changed

packages/react-reconciler/src/ReactFiber.js

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,11 @@ function FiberNode(
187187
// Learn more about this here:
188188
// https://github.com/facebook/react/issues/14365
189189
// https://bugs.chromium.org/p/v8/issues/detail?id=8538
190-
this.actualDuration = Number.NaN;
191-
this.actualStartTime = Number.NaN;
192-
this.selfBaseDuration = Number.NaN;
193-
this.treeBaseDuration = Number.NaN;
194-
195-
// It's okay to replace the initial doubles with smis after initialization.
196-
// This won't trigger the performance cliff mentioned above,
197-
// and it simplifies other profiler code (including DevTools).
198-
this.actualDuration = 0;
199-
this.actualStartTime = -1;
200-
this.selfBaseDuration = 0;
201-
this.treeBaseDuration = 0;
190+
191+
this.actualDuration = -0;
192+
this.actualStartTime = -1.1;
193+
this.selfBaseDuration = -0;
194+
this.treeBaseDuration = -0;
202195
}
203196

204197
if (__DEV__) {
@@ -286,10 +279,10 @@ function createFiberImplObject(
286279
};
287280

288281
if (enableProfilerTimer) {
289-
fiber.actualDuration = 0;
290-
fiber.actualStartTime = -1;
291-
fiber.selfBaseDuration = 0;
292-
fiber.treeBaseDuration = 0;
282+
fiber.actualDuration = -0;
283+
fiber.actualStartTime = -1.1;
284+
fiber.selfBaseDuration = -0;
285+
fiber.treeBaseDuration = -0;
293286
}
294287

295288
if (__DEV__) {
@@ -382,8 +375,8 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
382375
// This prevents time from endlessly accumulating in new commits.
383376
// This has the downside of resetting values for different priority renders,
384377
// But works for yielding (the common case) and should support resuming.
385-
workInProgress.actualDuration = 0;
386-
workInProgress.actualStartTime = -1;
378+
workInProgress.actualDuration = -0;
379+
workInProgress.actualStartTime = -1.1;
387380
}
388381
}
389382

packages/react-reconciler/src/ReactFiberBeginWork.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2430,10 +2430,10 @@ function mountSuspenseFallbackChildren(
24302430
// final amounts. This seems counterintuitive, since we're intentionally
24312431
// not measuring part of the render phase, but this makes it match what we
24322432
// do in Concurrent Mode.
2433-
primaryChildFragment.actualDuration = 0;
2434-
primaryChildFragment.actualStartTime = -1;
2435-
primaryChildFragment.selfBaseDuration = 0;
2436-
primaryChildFragment.treeBaseDuration = 0;
2433+
primaryChildFragment.actualDuration = -0;
2434+
primaryChildFragment.actualStartTime = -1.1;
2435+
primaryChildFragment.selfBaseDuration = -0;
2436+
primaryChildFragment.treeBaseDuration = -0;
24372437
}
24382438

24392439
fallbackChildFragment = createFiberFromFragment(
@@ -2560,8 +2560,8 @@ function updateSuspenseFallbackChildren(
25602560
// final amounts. This seems counterintuitive, since we're intentionally
25612561
// not measuring part of the render phase, but this makes it match what we
25622562
// do in Concurrent Mode.
2563-
primaryChildFragment.actualDuration = 0;
2564-
primaryChildFragment.actualStartTime = -1;
2563+
primaryChildFragment.actualDuration = -0;
2564+
primaryChildFragment.actualStartTime = -1.1;
25652565
primaryChildFragment.selfBaseDuration =
25662566
currentPrimaryChildFragment.selfBaseDuration;
25672567
primaryChildFragment.treeBaseDuration =

0 commit comments

Comments
 (0)