Optimization takeaways
- Always instantiate your object properties in the same order so that hidden classes, and subsequently optimized code, can be shared.
- Adding properties to an object after instantiation will force a hidden class change and slow down any methods that were optimized for the previous hidden class. Instead, assign all of an object’s properties in its constructor.
- Code that executes the same method repeatedly will run faster than code that executes many different methods only once (due to inline caching).
