Skip to content

Commit 7a48c90

Browse files
authored
Prevent a v8 deopt when profiling (#14383)
1 parent e382b0b commit 7a48c90

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

packages/react-reconciler/src/ReactFiber.js

+17
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ function FiberNode(
254254
this.alternate = null;
255255

256256
if (enableProfilerTimer) {
257+
// Note: The following is done to avoid a v8 deopt.
258+
//
259+
// It is important to initialize the fields below with doubles.
260+
// Otherwise Fibers will deopt and end up having separate shapes when
261+
// doubles are later assigned to fields that initially contained smis.
262+
// This is a bug in v8 having something to do with Object.preventExtension().
263+
//
264+
// Learn more about this deopt here:
265+
// https://github.com/facebook/react/issues/14365
266+
// https://bugs.chromium.org/p/v8/issues/detail?id=8538
267+
this.actualDuration = Number.NaN;
268+
this.actualStartTime = Number.NaN;
269+
this.selfBaseDuration = Number.NaN;
270+
this.treeBaseDuration = Number.NaN;
271+
272+
// It's okay to replace the initial doubles with smis after initialization.
273+
// This simplifies other profiler code and doesn't trigger the deopt.
257274
this.actualDuration = 0;
258275
this.actualStartTime = -1;
259276
this.selfBaseDuration = 0;

0 commit comments

Comments
 (0)