– Variable inside javascript: Data Reference. – How to locate a variable in functions: From Local to Global – What does the VM do before execution a function? • Create a stackframe before getting into functions • Reference all the outer function variables by pointers to array in stackframe • Referencing local variables in stackframe • Push stackframe into vm's execution context • All the stackframes => Scope Chain – What does the VM do during execution ?
• All the variables is looked up inside the scope chain as less times as possible. • Once referenced, cached it! • Check the type & avaibilities on the fly with minus cost (usually assembly code) – The state of art javascript vm supporting jit! What matters ? – Calling slower routings (exception blow up) – Variable type changed during executions (delete a.b)
Object property • Nearly the same. Thanks to hidden class and jit. • A hidden class is some hint that provide the jit how to access the property data inside a object. – Array item vs Object property • Object is faster than array in dealing with sparse data.
– for (A in B )? • Same: – Pickout A from B each loop – Create reference on the fly • Diff: – foreach use iterator & generator – for-in track whether this property is enumable. – Using normal while/for loop will be better. For / While – For vs While – It is nearly the same
JavaScript Performance Boost? – fib normal vs asm • Using asmjs slower! (Due to compilation overhead) • DFG etc is enough to find out the data types. – asm vs no-asm Conclusion – Better NOT use it now!