Become a member
Sign in
Donghyun Seo
Donghyun Seo

Donghyun Seo

6 Following
4 Followers
  • Profile

  • Highlights

Highlighted by Donghyun Seo

See more

From How JavaScript works: inside the V8 engine + 5 tips on how to write optimized code by Alexander Zlatkov

…, “p1” and “p2” end up with different hidden classes as a result of the different transition paths. In such cases, it’s much better to initialize dynamic properties in the same order so that the hidden classes can be reused.

From How JavaScript works: inside the V8 engine + 5 tips on how to write optimized code by Alexander Zlatkov

Tagged values: V8 represents objects and numbers with 32 bits. It uses a bit to know if it is an object (flag = 1) or an integer (flag = 0) called SMI (SMall Integer) because of its 31 bits. Then, if a numeric value is bigger than 31 bits, V8 will box the number, turning it into a double and creating a new object to put the number inside. Try to use 31 bit signed numbers whenever possible to avoid the expensive boxing operation into a JS object.

From How JavaScript works: inside the V8 engine + 5 tips on how to write optimized code by Alexander Zlatkov

Arrays: avoid sparse arrays where keys are not incremental numbers. Sparse arrays which don’t have every element inside them are a hash table. Elements in such arrays are more expensive to access. Also, try to avoid pre-allocating large arrays. It’s better to grow as you go. Finally, don’t delete elements in arrays. It makes the keys sparse.