Home

Awesome

V8 bailout reasons

A list of Crankshaft bailout reasons with examples, explanations and advices.

Unless otherwise specified, the following are Crankshaft bailouts.

Warning!

Starting from Chrome 59 and Node.js 8.3.0, Crankshaft is not used anymore. It uses TurboFan instead.

The content of this repository only applies to Crankshaft. If the JavaScript engine you are targeting does not use Crankshaft as its optimizing compiler, you should not care about this repository and the advices present in there. This repository will stay here for historical reasons, it still has documentation value.

What this is about

In order to keep this section short and allow people to get to the primary content of this repo faster, here is what it's all about and why you (probably) should care if you are using Crankshaft: Chromium, Chrome, Node.js, V8, Crankshaft and bailout reasons.

Index

Bailout reasons

References

Bailout reasons

Assignment to parameter in arguments object

Only happens if you reassign to a parameter while also mentioning arguments in the function. More info.

// sloppy mode only
function test(a) {
  if (arguments.length < 2) {
    a = 0;
  }
}

Bad value context for arguments value

// strict & sloppy modes
function test1() {
  arguments[0] = 0;
}

// strict & sloppy modes
function test2() {
  arguments.length = 0;
}

// strict & sloppy modes
function test3() {
  return arguments;
}

// strict & sloppy modes
function test4() {
  var args = [].slice.call(arguments);
}

// strict & sloppy modes
function test5() {
  var a = arguments;
  return function() {
    return a;
  };
}

ForInStatement with non-local each variable

// strict & sloppy modes
function test1() {
  var obj = {};
  for(key in obj);
}

// strict & sloppy modes
function key() {
  return 'a';
}
function test2() {
  var obj = {};
  for(key in obj);
}

Inlining bailed out

Courtesy of @kangax

// strict & sloppy modes
var obj = { prop1: ... };

function test(param) {
  param.prop2 = ...; // Inlining bailed out
}
test(obj);

// strict & sloppy modes
var obj = { prop1: ... };

function someMethodThatAssignsSomeOtherProp(param) {
  param.someOtherProp = ...; // Inlining bailed out
}

function test(param) {
  someMethodThatAssignsSomeOtherProp(param);
}

f(obj);

Object literal with complex property

// strict & sloppy modes
function test() {
  return {
    __proto__: 3
  };
}

Optimized too many times

// strict & sloppy modes
// No known canonical reproduction

Reference to a variable which requires dynamic lookup

// sloppy mode only
function test() {
  with ({x:1}) {
    return x;
  }
}

Rest parameters

// strict & sloppy modes
function test(...rest) {
  return rest[0];
}

Smi addition overflow

Smi addition overflow

function add(a, b) {
  return a + b;
}

add(1, 2);
add(1, 2);
%OptimizeFunctionOnNextCall(add);
add(2 ** 31 - 2, 20);

Smi subtraction overflow

function subtract(a, b) {
  return a - b;
}

subtract(1, 2);
subtract(1, 2);
%OptimizeFunctionOnNextCall(subtract);
subtract(-3, 2 ** 31 - 1);

Too many parameters

// strict & sloppy modes
function test(p1, p2, p3, ..., p512) {
}

TryCatchStatement

// strict & sloppy modes
function test() {
  return 3;
  try {} catch(e) {}
}

TryFinallyStatement

// strict & sloppy modes
function test() {
  return 3;
  try {} finally {}
}

Unsupported phi use of arguments

// strict & sloppy modes
function test1() {
  var _arguments = arguments;
  if (0 === 0) { // anything evaluating to true, except a number or `true`
    _arguments = [0]; // Unsupported phi use of arguments
  }
}

// strict & sloppy modes
function test2() {
  var _arguments = arguments;
  for (var i = 0; i < 1; i++) {
    _arguments = [0]; // Unsupported phi use of arguments
  }
}

// strict & sloppy modes
function test3() {
  var _arguments = arguments;
  var again = true;
  while (again) {
    _arguments = [0]; // Unsupported phi use of arguments
    again = false;
  }
}

Unsupported phi use of const or let variable

function test() {
  for (let i = 0; i < 0; i++) {
    const x = __lookupGetter__; // `__lookupGetter__` and
  }
  const self = this; // `this` should both be present for this to happen
}

Yield

// strict & sloppy modes
function* test() {
  yield 0;
}

References

Resources

All bailout reasons