Skip to content

Commit

Permalink
Prevent a v8 deopt when profiling (facebook#14383)
Browse files Browse the repository at this point in the history
  • Loading branch information
bvaughn authored and trueadm committed Dec 14, 2018
1 parent d3c611a commit 465b2d8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/react-reconciler/src/ReactFiber.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,23 @@ function FiberNode(
this.alternate = null;

if (enableProfilerTimer) {
// Note: The following is done to avoid a v8 deopt.
//
// It is important to initialize the fields below with doubles.
// Otherwise Fibers will deopt and end up having separate shapes when
// doubles are later assigned to fields that initially contained smis.
// This is a bug in v8 having something to do with Object.preventExtension().
//
// Learn more about this deopt 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 simplifies other profiler code and doesn't trigger the deopt.
this.actualDuration = 0;
this.actualStartTime = -1;
this.selfBaseDuration = 0;
Expand Down

0 comments on commit 465b2d8

Please sign in to comment.