Javascript Optimization Takeaway

Optimization takeaways

  1. Always instantiate your object properties in the same order so that hidden classes, and subsequently optimized code, can be shared.
  2. 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.
  3. Code that executes the same method repeatedly will run faster than code that executes many different methods only once (due to inline caching).

Leave a comment