mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
[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 https://github.com/facebook/react/issues/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.
This commit is contained in:
+10
-17
@@ -187,18 +187,11 @@ function FiberNode(
|
||||
// Learn more about this here:
|
||||
// https://github.com/facebook/react/issues/14365
|
||||
// https://bugs.chromium.org/p/v8/issues/detail?id=8538
|
||||
this.actualDuration = Number.NaN;
|
||||
this.actualStartTime = Number.NaN;
|
||||
this.selfBaseDuration = Number.NaN;
|
||||
this.treeBaseDuration = Number.NaN;
|
||||
|
||||
// It's okay to replace the initial doubles with smis after initialization.
|
||||
// This won't trigger the performance cliff mentioned above,
|
||||
// and it simplifies other profiler code (including DevTools).
|
||||
this.actualDuration = 0;
|
||||
this.actualStartTime = -1;
|
||||
this.selfBaseDuration = 0;
|
||||
this.treeBaseDuration = 0;
|
||||
this.actualDuration = -0;
|
||||
this.actualStartTime = -1.1;
|
||||
this.selfBaseDuration = -0;
|
||||
this.treeBaseDuration = -0;
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
@@ -286,10 +279,10 @@ function createFiberImplObject(
|
||||
};
|
||||
|
||||
if (enableProfilerTimer) {
|
||||
fiber.actualDuration = 0;
|
||||
fiber.actualStartTime = -1;
|
||||
fiber.selfBaseDuration = 0;
|
||||
fiber.treeBaseDuration = 0;
|
||||
fiber.actualDuration = -0;
|
||||
fiber.actualStartTime = -1.1;
|
||||
fiber.selfBaseDuration = -0;
|
||||
fiber.treeBaseDuration = -0;
|
||||
}
|
||||
|
||||
if (__DEV__) {
|
||||
@@ -382,8 +375,8 @@ export function createWorkInProgress(current: Fiber, pendingProps: any): Fiber {
|
||||
// This prevents time from endlessly accumulating in new commits.
|
||||
// This has the downside of resetting values for different priority renders,
|
||||
// But works for yielding (the common case) and should support resuming.
|
||||
workInProgress.actualDuration = 0;
|
||||
workInProgress.actualStartTime = -1;
|
||||
workInProgress.actualDuration = -0;
|
||||
workInProgress.actualStartTime = -1.1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-6
@@ -2430,10 +2430,10 @@ function mountSuspenseFallbackChildren(
|
||||
// final amounts. This seems counterintuitive, since we're intentionally
|
||||
// not measuring part of the render phase, but this makes it match what we
|
||||
// do in Concurrent Mode.
|
||||
primaryChildFragment.actualDuration = 0;
|
||||
primaryChildFragment.actualStartTime = -1;
|
||||
primaryChildFragment.selfBaseDuration = 0;
|
||||
primaryChildFragment.treeBaseDuration = 0;
|
||||
primaryChildFragment.actualDuration = -0;
|
||||
primaryChildFragment.actualStartTime = -1.1;
|
||||
primaryChildFragment.selfBaseDuration = -0;
|
||||
primaryChildFragment.treeBaseDuration = -0;
|
||||
}
|
||||
|
||||
fallbackChildFragment = createFiberFromFragment(
|
||||
@@ -2560,8 +2560,8 @@ function updateSuspenseFallbackChildren(
|
||||
// final amounts. This seems counterintuitive, since we're intentionally
|
||||
// not measuring part of the render phase, but this makes it match what we
|
||||
// do in Concurrent Mode.
|
||||
primaryChildFragment.actualDuration = 0;
|
||||
primaryChildFragment.actualStartTime = -1;
|
||||
primaryChildFragment.actualDuration = -0;
|
||||
primaryChildFragment.actualStartTime = -1.1;
|
||||
primaryChildFragment.selfBaseDuration =
|
||||
currentPrimaryChildFragment.selfBaseDuration;
|
||||
primaryChildFragment.treeBaseDuration =
|
||||
|
||||
Reference in New Issue
Block a user