0

I understand that js' JIT compiler will deoptimize the warm or hot code in case datatype changes in a loop (like one element in array is string whereas rest were int).

But i have few scenarios where i'm not able to understand will the code be deoptimized or not

  • Same loop is used for two arrays where one array contains strings and other ints. Will compiler deoptimize the code here or create two copies? (I understand it should be two copies).
  • In case of array of object. Considering all scenarios like
    • Manipulated sub-property is of different type.
    • Same sub-properties for each object but one object has one property missing.
      • Missing property is not manipulated inside the loop.
      • Missing property is manipulated inside loop (null case is handled).
    • All objects have different properties (New property is added, or manipulation is done using property location).
a1626
  • 2,953
  • 1
  • 19
  • 34
  • 1
    It's implementation specific. v8, SpiderMonkey, Chakra, JavaScriptCore (aka Nitro), they all implement it differently. You would need to go in a per implementation basis as the ECMA standard doesn't really dictate a way to implement them. – arboreal84 May 28 '17 at 12:00
  • v8 will even deoptimize a function if you add comments to it since comments count as a part of function length. – arboreal84 May 28 '17 at 12:01
  • From comments? won't comments be there from very beginning? – a1626 May 28 '17 at 12:02
  • Oh, correct. I meant, comments or passing a function length threshold would cause it to not be optimized. – arboreal84 May 28 '17 at 12:02
  • oh. So you are saying that there is a chance that deoptimization might occur for all of these cases or none of these cases depending on the engine. Or is there some case where it will always happen or never happen for all the major engines. – a1626 May 28 '17 at 12:05
  • They sometimes borrow concepts from each other. In some cases they have a common ancestor... for v8, the JIT (Turbofan) is documented here: https://github.com/v8/v8/wiki/TurboFan#turbofan-design-documents – arboreal84 May 28 '17 at 12:11
  • I think the most important thing to understand: A deoptimisation will only occur for code that was optimised in the first place. And it will happen whenever the assumptions that the optimiser made are not met. – Bergi May 28 '17 at 12:46
  • @Bergi i do understand that part (atleast i think so). That's why i mentioned `warm or hot` code in my question. But thanks for the tip. – a1626 May 28 '17 at 12:48

0 Answers0