This question already has an answer here:
How can % signs be used in identifiers
(1个答案)
3年前关闭。
我正在阅读有关优化技术的this article,其中包含以下代码:
我有两个问题:
函数
(1个答案)
3年前关闭。
我正在阅读有关优化技术的this article,其中包含以下代码:
//Function that contains the pattern to be inspected (using an `eval` statement)
function exampleFunction() {
return 3;
eval('');
}
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;
}
}
//Fill type-info
exampleFunction();
// 2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic
exampleFunction();
%OptimizeFunctionOnNextCall(exampleFunction);
//The next call
exampleFunction();
//Check
printStatus(exampleFunction);
我有两个问题:
函数
%GetOptimizationStatus
和%OptimizeFunctionOnNextCall
从未定义,它们从何而来?2 calls are needed to go from uninitialized -> pre-monomorphic -> monomorphic
是什么意思? 最佳答案
设置指定的优化标志时,将%GetOptimizationStatus
和%OptimizeFunctionOnNextCall
注入到Node中。
从根本上讲,单态部分表示优化器只有在检测到多次使用后才能启动。.在激活此TurboFan之后。
IOW:如果查看输出,您会注意到它两次调用了exampleFunction(禁用了优化),并且只有在第三次尝试时,TurboFan才会启动。
09-26 04:58