vhf/v8-bailout-reasons

'Bad value context for arguments value': additional precaution

vsemozhetbyt opened this issue · 0 comments

I've tried to reduce the case reported in this comment.

It seems in addition to the precautions mentioned here there is another one:

  • Never use a direct function call with arguments[i] (i.e. arguments[i]()); use an intermediate variable instead (i.e. const arg = arguments[i]; arg();).

This case is valid even for a function call in a dead code, without an actual function call in the runtime.

Code to confirm the precaution:

'use strict';

function mainFuncGood() {
  const arg0 = arguments[0];
  if (0 === 1) arg0();
}

function mainFuncBad() {
  if (0 === 1) arguments[0](); // must be op, simple `if (false)` will not do for bailout
}

function paramFunc() {}

for (let i = 0; i < 1e3; i++) mainFuncGood(paramFunc);

for (let i = 0; i < 1e3; i++) mainFuncBad(paramFunc);
node --trace_opt --trace_deopt test.js

[marking 000002685E5E0B51 <JS Function mainFuncGood (SharedFunctionInfo 000003ED2AE67B21)> for optimized recompilation, reason: small function, ICs with typeinfo: 2/3 (66%), generic ICs: 0/3 (0%)]
[compiling method 000002685E5E0B51 <JS Function mainFuncGood (SharedFunctionInfo 000003ED2AE67B21)> using Crankshaft]
[optimizing 000002685E5E0B51 <JS Function mainFuncGood (SharedFunctionInfo 000003ED2AE67B21)> - took 0.147, 0.121, 0.053 ms]
[completed optimizing 000002685E5E0B51 <JS Function mainFuncGood (SharedFunctionInfo 000003ED2AE67B21)>]

[marking 000002685E5E0B99 <JS Function mainFuncBad (SharedFunctionInfo 000003ED2AE67BE1)> for optimized recompilation, reason: small function, ICs with typeinfo: 1/3 (33%), generic ICs: 0/3 (0%)]
[compiling method 000002685E5E0B99 <JS Function mainFuncBad (SharedFunctionInfo 000003ED2AE67BE1)> using Crankshaft]
[disabled optimization for 000003ED2AE67BE1 <SharedFunctionInfo mainFuncBad>, reason: Bad value context for arguments value]