1
[compiling method 0x21c8ad010a59 <JS Function cbInTest (SharedFunctionInfo 0xa46935601e1)> using Crankshaft]
[optimizing 0x21c8ad010a59 <JS Function cbInTest (SharedFunctionInfo 0xa46935601e1)> - took 0.040, 0.242, 0.094 ms]
Function is optimized
2
[found optimized code for 0x21c8ad09f081 <JS Function cbInTest (SharedFunctionInfo 0xa46935601e1)>]
Function is optimized
3
[found optimized code for 0x21c8ad09f0c9 <JS Function cbInTest (SharedFunctionInfo 0xa46935601e1)>]
Function is optimized
function printStatus(fn) {
switch (%GetOptimizationStatus(fn)) {
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;
case 7: console.log("Function is optimized by TurboFan"); break;
default: console.log("Unknown optimization status"); break;
}
}
var EventEmitter = require('events').EventEmitter;
var e = new EventEmitter();
function My(name) {
this.name = name;
}
function test(name) {
var obj = new My(name);
e.once('test', function cbInTest(self) {
if (self) return;
console.log(obj.name);
cbInTest(true);
cbInTest(true);
%OptimizeFunctionOnNextCall(cbInTest);
cbInTest(true);
printStatus(cbInTest);
});
}
test(1);
test(2);
test(3);
e.emit('test');
node --trace_opt --trace_deopt --allow-natives-syntax test.js
[optimizing 0x21c8ad010a59 <JS Function cbInTest (SharedFunctionInfo 0xa46935601e1)> - took 0.040, 0.242, 0.094 ms]
говорит о том, что движок создаёт одну общую функцию, а затем использует её повторно: [found optimized code for 0x21c8ad09f081 <JS Function cbInTest (SharedFunctionInfo 0xa46935601e1)>]
[found optimized code for 0x21c8ad09f0c9 <JS Function cbInTest (SharedFunctionInfo 0xa46935601e1)>]