tessel / t2-cli

Tessel 2 Command Line Interface
MIT License
114 stars 56 forks source link

Tessel v8 Aborts Optimization With No Reason #1117

Open v0lkan opened 7 years ago

v0lkan commented 7 years ago

Summary

I’m not sure if this is the correct Github project; if it’s not feel free to guide me to the correct one.

Here’s what I’m doing:

1) Root into a Tessel 2 2) vi 000_add.js and save the following script into /:

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;
    }
}

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

add( 1, 2 );
add( 1, 2 );

%OptimizeFunctionOnNextCall(add)
console.log('----');
add( 1, 2 );

printStatus(add);

3) Execute node --trace-opt --trace-deopt --allow-natives-syntax 000_add.js

I get the following output on the console:

[disabled optimization for 0x2ff2a4b1 <SharedFunctionInfo SAR>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff29b69 <SharedFunctionInfo ADD>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff29df1 <SharedFunctionInfo SUB>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff29ec9 <SharedFunctionInfo MUL>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff593d1 <SharedFunctionInfo>, reason: TryCatchStatement]
[disabled optimization for 0x2ff56a41 <SharedFunctionInfo FormatMessage>, reason: TryCatchStatement]
[disabled optimization for 0x2ff2a589 <SharedFunctionInfo SHR>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff2a6cd <SharedFunctionInfo IN>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff67281 <SharedFunctionInfo NativeModule.require>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff66bc1 <SharedFunctionInfo NativeModule>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff6765d <SharedFunctionInfo NativeModule.compile>, reason: TryFinallyStatement]
[disabled optimization for 0x2ff2a151 <SharedFunctionInfo BIT_OR>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x3574f5fd <SharedFunctionInfo createBuffer>, reason: TryFinallyStatement]
[disabled optimization for 0x357530f1 <SharedFunctionInfo exports.deprecate>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff2a661 <SharedFunctionInfo DELETE>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff3588d <SharedFunctionInfo Join>, reason: TryFinallyStatement]
[disabled optimization for 0x357686ad <SharedFunctionInfo Module._load>, reason: TryFinallyStatement]
[disabled optimization for 0x2ff2a229 <SharedFunctionInfo BIT_AND>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x3576cd45 <SharedFunctionInfo fs.readFileSync>, reason: TryFinallyStatement]
[disabled optimization for 0x2ff2a079 <SharedFunctionInfo MOD>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff2a955 <SharedFunctionInfo APPLY_PREPARE>, reason: Call to a JavaScript runtime function]
[disabled optimization for 0x2ff2a301 <SharedFunctionInfo BIT_XOR>, reason: Call to a JavaScript runtime function]
----
[aborted optimizing 0x768a4dc1 <JS Function add (SharedFunctionInfo 0x35783165)> because: no reason]
Function is never optimized
[disabled optimization for 0x35762f15 <SharedFunctionInfo nextTickCallbackWithManyArgs>, reason: TryFinallyStatement]

So v8 aborts optimization even with the simplest function without giving any reason (see the output after ---)

For reference if I run the same command in Raspberry Pi, I get the following output:

root@raspberrypi:~/fluent# node --trace-opt-verbose --trace-deopt --allow-natives-syntax 000_add.js
[compiling method 0x4909c1b1 <JS Function add (SharedFunctionInfo 0x38d3fe19)> using Crankshaft]
[optimizing 0x4909c1b1 <JS Function add (SharedFunctionInfo 0x38d3fe19)> - took 0.313, 0.709, 0.415 ms]
Function is optimized

One thing that grabs my attention is I get a much shorter output in raspberry pi, although the script that I execute is identical. — And also raspberry pi properly optimizes the function.

I suspect that the optimization bailout might be due to Tessel’s MIPS architecture, though it would be lovely if a subject matter expert can chime in and enlighten on

Expectation

What happens: Tessel’s v8 runtime bails out optimization without giving a reason, even if it is explicitly forced to do the optimization.

Expectation: Tessel’s v8 runtime should optimize the called function.

HipsterBrown commented 7 years ago

Hi @v0lkan. Thank you so much for the in-depth write-up, it's very helpful. The Tessel team is pretty spread out during the holidays, so there's been a bit of a delay in responding to this. We will be checking this out and would love to work with you on this in the New Year. :smile:

v0lkan commented 7 years ago

Hi @HipsterBrown, no worries; and happy new year!

It would be lovely to help make Tessel faster.

If we can enable v8 optimizations, that might even be a part of my (probably upcoming) Fluent 2017 tech talk on June 2017.

Excited and curious about how this issue will pan out.

Let me know if there’s anything I can do to help.

I have a Tessel 1, Tessel 2, a rasberry pi, an intel nuc, and a bunch of other gizmos that I can use as a guinea pig.

Cheers,

Volkan.

rwaldron commented 7 years ago

I’m not sure if this is the correct Github project; if it’s not feel free to guide me to the correct one.

It's not whether this is the correct place or not, it's whether there is anything we can actually do about it (besides investigate together). I'm not sure where the correct place would be—more on this to follow.

I suspect that the optimization bailout might be due to Tessel’s MIPS architecture ... why cannot Tessel’s v8 runtime Optimize JavaScript?

I found these, which are interesting:

I'm still digging, but I need to change gears for a few hours and didn't want to leave this unposted

v0lkan commented 7 years ago

Hey @HipsterBrown @rwaldron — do you have any update on this? — Will she live, doctor?

rwaldron commented 7 years ago

Sorry, I haven't made any progress here.