link: https://mathiasbynens.be/notes/shapes-ics
JavaScript Engines:
- V8; NodeJS
- SpiderMoney; SpiderNode
- Charkra; Node Charkra
- JSC: powering Safari & React Native
JS source code -> parser -> Abstract Sytax Tree
Interpreter -> bytecode | (when func gets hot) | (deoptimizing) optimizing compiler -> optimized code
All js object are dictionaries with string keys, and the string keys map to a value called Property attributes. [MDN-Object.defineProperty] (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty)
Property attributes can store:
- Writeable: the properity can be reassigned to.
- Enumberable: the properity can show up in fo-in loop.
- Configurable: it is deletable properity.
obj = Object.defineProperties({}, {
a: {
value: 1,
writable: false,
enumerable: true,
configurable: false
},
});
obj.a = 11;
console.log(obj.a); // 1
delete obj.a;
console.log(obj.a); // 1
for(let x in obj) {
console.log(x); // a
}
- The upper limit size of the array is 2^32 - 1
new Array(2**32)
// Uncaught RangeError: Invalid array length
- Always initialize objects in the same way, so that they don't end up with different sharps
The ingredient to make JS run fast.
- Don't mess up with the property attributes of array elements, so that they can be stored and operated efficiently.
- Avoid using Object.defineProperty in array index
- It blows up the element backing store and turns the whole thing into an object