Learn JavaScript

Lesson 5 of 9 · Performance, Memory, Debugging and the Interview Output Puzzles

Module 17 · Performance, Memory, Debugging and the Interview Output Puzzles

Under the Hood: V8's Compilers, Hidden Classes and the Garbage Collector

ProReading

Zara has a strange measurement. She times the same function twenty times in a row, and the first time is several times slower than the rest. Then she builds two lists of objects with the same data, and summing one is slower than summing the other. Nothing in her code explains either result.

Checking what this lesson needs for you…

What is inside Under the Hood: V8's Compilers, Hidden Classes and the Garbage Collector

  1. Four tiers: why code gets faster as it runs
  2. Optimised code rests on guesses
  3. Hidden classes: an object's shape
  4. Inline caches: one shape is fast
  5. Packed and holey arrays
  6. The garbage collector: what is reachable stays
  7. Young and old space
  8. A leak is a reference you forgot
  9. WeakMap and WeakRef
  10. The lab: what does a small object cost?