Q68: How do V8 Hidden Classes (Shapes) and Inline Caches affect Node.js performance?

V8 dynamic optimization relies on Hidden Classes (also called Shapes) and Inline Caches (IC). When JavaScript objects share identical property structure and initialization order, V8 assigns them the same Hidden Class, enabling fast memory offset property lookups. If dynamic properties are added out of order or deleted (delete obj.prop), V8 creates new shapes or downgrades the property lookup to dictionary mode, slowing down property accesses.

Key Takeaways
  • Initialize object properties in a consistent order to help V8 reuse Hidden Classes.
  • Avoid deleting properties (delete obj.prop); assign undefined or null instead to maintain optimized execution paths.
Knowledge Check

Why is deleting an object property using `delete obj.key` considered harmful for high-performance Node.js code?