@samitouri / QOS-React / commits / 7a48c900b7

Prevent a v8 deopt when profiling (#14383)

Brian Vaughn committed Dec 3, 2018 at 09:22 UTC 7a48c900b7d8c97580d62adfa3625a7b7567c998
1 file changed +17
packages/react-reconciler/src/ReactFiber.js
+17
@@ -254,6 +254,23 @@ function FiberNode(
254 this.alternate = null;
255
256 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.
274 this.actualDuration = 0;
275 this.actualStartTime = -1;
276 this.selfBaseDuration = 0;