Q45: How do V8 Hidden Classes (Shapes) optimize property access speed?

V8 assigns Hidden Classes (Shapes) to objects. When objects share identical key property structures and declaration order, V8 reuses the same Hidden Class, enabling fast memory offset property lookups instead of dictionary hash lookups.

Key Takeaways
  • Instantiate object properties in consistent order to reuse V8 shapes.
  • Avoid deleting properties (delete obj.prop) to prevent downgrading to slow dictionary mode.
Knowledge Check

How should you nullify an object key without invalidating its V8 Hidden Class shape?