Skip to content

Instantly share code, notes, and snippets.

@fengmk2
Created April 29, 2016 03:00
Show Gist options
  • Save fengmk2/adad365d273d5dd33df6423262ba22cd to your computer and use it in GitHub Desktop.
Save fengmk2/adad365d273d5dd33df6423262ba22cd to your computer and use it in GitHub Desktop.
optimized-test.js
'use strict';
// http://dev.zm1v1.com/2015/08/19/javascript-optimization-killers/?spm=0.0.0.0.Rxyzi2
function testFn(a, b) {
const c = (a || 0) + (b || 1);
return c;
}
function printStatus(fn) {
var status = %GetOptimizationStatus(fn);
switch(status) {
case 1: console.log("Function is optimized"); break;
case 2: console.log("Function is not optimized"); break;
case 3: console.log("Function is always optimized"); break;
case 4: console.log("Function is never optimized"); break;
case 6: console.log("Function is maybe deoptimized"); break;
default: console.log("Unknow GetOptimizationStatus %s", status); break;
}
}
console.log('node %s', process.version);
console.log(testFn.toString());
testFn();
testFn();
%OptimizeFunctionOnNextCall(testFn);
testFn();
printStatus(testFn);
// $ node --trace_opt --trace_deopt --allow-natives-syntax optimized-test.js
@fengmk2
Copy link
Author

fengmk2 commented Apr 29, 2016

node --trace_opt --trace_deopt --allow-natives-syntax optimized-test.js
[disabled optimization for 0x166581c47af1 <SharedFunctionInfo SAR>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c466b9 <SharedFunctionInfo ADD>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c47d59 <SharedFunctionInfo SHR>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c48079 <SharedFunctionInfo IN>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581cc0281 <SharedFunctionInfo NativeModule.require>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581cbf801 <SharedFunctionInfo NativeModule>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c473d1 <SharedFunctionInfo BIT_OR>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c46e49 <SharedFunctionInfo MUL>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581cd6959 <SharedFunctionInfo exports.deprecate>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c47fb1 <SharedFunctionInfo DELETE>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c51b59 <SharedFunctionInfo Join>, reason: TryFinallyStatement]
[disabled optimization for 0x166581c46bf1 <SharedFunctionInfo SUB>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x1bc7211b69 <SharedFunctionInfo Module._load>, reason: TryFinallyStatement]
[disabled optimization for 0x166581c47629 <SharedFunctionInfo BIT_AND>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x1bc7218de1 <SharedFunctionInfo fs.readFileSync>, reason: TryFinallyStatement]
[disabled optimization for 0x166581c47239 <SharedFunctionInfo MOD>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c48651 <SharedFunctionInfo APPLY_PREPARE>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x166581c477c1 <SharedFunctionInfo BIT_XOR>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x1bc725c261 <SharedFunctionInfo>, reason: TryCatchStatement]
[disabled optimization for 0x166581c48209 <SharedFunctionInfo INSTANCE_OF>, reason: Call to a JavaScript runtime function]
node v4.4.3
function testFn(a, b) {
  const c = (a || 0) + (b || 1);
  return c;
}
[compiling method 0x2f01a2087ad9 <JS Function testFn (SharedFunctionInfo 0x1bc723df69)> using Crankshaft]
[optimizing 0x2f01a2087ad9 <JS Function testFn (SharedFunctionInfo 0x1bc723df69)> - took 0.050, 0.078, 0.041 ms]
Function is optimized
[disabled optimization for 0x1bc7208e91 <SharedFunctionInfo nextTickCallbackWithManyArgs>, reason: TryFinallyStatement]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment