node.js - Javascript deoptimization -


I'm not sure what is wrong with this code I Src is a Uint8Array object, which Is greater than 0.

  function makeImageFromChannel (src) {var image = new Uint8Array (src.length * 4), i = 0, index = 0, value = 0; Console.log (src.BYTES_PER_ELEMENT) for console.log (src.map) (i = 0; i & lt; src.length; i ++) {value = src [i] | 0; Image [index] = value; Image [index 1] = value; Image [index + 2] = value; Image [index + 3] = 255; Index = 4; } Return image; } Var vars = new Uint8Array (23034); For (var i = 0; i   

I can read several times in the terminal when I run this command node --trace_deopt --allow-natives-syntax script.js .

  [deoptimizing: start 0x36125ec63a21 makeImageFromChannel @ 13] translating makeImageFromChannel = & gt; Node = 59, height = 24 0x7fff5fbfe798: [top + 64] & lt; - 0x3feb15c04121; R8 0x3feb15c04121 & lt; Undefined & gt; 0x7fff5fbfe790: [top + 56] & lt; - 0x2bc986d 9ffc1; Rdi 0x2bc986d 9ffc1 & lt; A Uint8Array & gt; 0x7fff5fbfe788: [top + 48] & lt; - 0x2ea32af21c29; Caller PC 0x7fff5fbfe780: [top + 40] & lt; - 0x7fff5fbfe808; Caller FP0x7fff5fbfe778: [top + 32] & lt; - 0x3feb15c414b1; Reference 0x7fff5fbfe770: [top + 24] & lt; - 0x36125ec63a21; Function 0x7fff5fbfe768: [top + 16] & lt; - 0x2bc986c218d1; Rdx 0x2bc986c218d1 & lt; A Uint8Array & gt; 0x7fff5fbfe760: [top + 8] & lt; - 135448; Rbx (SMI) 0x7fff5fbfe758: [top + 0]   

I understand how to find it Not sure there is an undefined value

For some reasons, V8 is such that an array of such Usage A function will be deoptimized:

 for  (i = 0; i & lt; src.length; i ++) {value = src [i] | 0; Image [index] = value; Image [index 1] = value; Image [index + 2] = value; Image [index + 3] = 255; Index = 4; }   

V8 to not deoptimize this function, if you can rearrange the appearance in the opposite order like this:

  image [ Index + 3] = 255; Image [index + 2] = value; Image [index 1] = value; Image [index] = value;   

and V8 will be happy it seems more or less like a bug in v8 engines than anything else. The engine should find out that there is no effect on the results in these 4 lines sequence. That means that the V8 function should be able to optimize even if the lines were in any order.

It is also not clear how spidermonkey optimize or not those rows.

I can better answer why V8 gets deoptimized.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -