# Proxy Traps and Reflect Internals vs V8 Hidden Classes (Shapes) and Inline Caches

- **Canonical URL:** https://frontend.rocks/vs/proxy-reflect-internals-vs-v8-hidden-classes-ic/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** Plain objects hit monomorphic Inline Caches via Shapes, whereas Proxy traps intercept lookups and bypass ICs.

## Comparison Matrix

| Dimension | Proxy Traps and Reflect Internals | V8 Hidden Classes (Shapes) and Inline Caches |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Baseline · Widely |
| **Domain** | JS Runtime | JS Runtime |
| **Mental Model** | Build fine-grained reactivity without breaking inherited getters—Proxy traps intercept [[Get]]/[[Set]] while Reflect forwards receiver binding, at the cost of bypassing V8 Inline Caches. | Internal descriptors (Maps/Shapes) generated by JS engines to read object properties at fixed memory offsets instead of hash-table lookups. |
| **Prerequisites** | Prototype Chain Lookup and Delegation (Proxy traps intercept [[Get]] and [[GetPrototypeOf]] before ordinary prototype traversal runs.) | Event Loop, Macrotasks, and Microtask Queue (Hot code executed inside JS tasks is optimized by Ignition and TurboFan.) |
| **When Not to Use** | When not to use Proxy: Never wrap large numerical arrays or 60 fps particle buffers in a Proxy; the trap overhead dwarfs the computation. | When not to use manual Shape optimization: For configuration objects read once at startup, readability comes first; enforce strict Shapes only in hot loops (parsers, renderers, per-frame math), and keep Proxy Traps out of those hot loops. |

## Proxy Traps and Reflect Internals — Under the Hood
V8 marks a `Proxy` as an exotic `JSProxy` object, routing `[[Get]]`, `[[Set]]`, and `[[OwnPropertyKeys]]` out of [V8 Inline Caches](/concepts/v8-hidden-classes-ic) into JS trap functions. Every intercepted read pays trap dispatch and invariant-verification overhead, and forwarding via `Reflect` preserves the `receiver` binding for inherited getters.

1. **Exotic Dispatch**: V8 marks the wrapper as a `JSProxy`, routing property reads out of [Inline Caches](/concepts/v8-hidden-classes-ic) into JS trap handlers.
2. **Receiver Preservation**: Passing `receiver` to `Reflect.get(target, key, receiver)` ensures inherited getters read reactive properties on the proxy, not the raw target.
3. **Invariant Checks**: After a trap returns, the engine enforces spec invariants (e.g., a non-writable, non-configurable property cannot report a different value).

```js
function trackReads(target, onRead) {
  return new Proxy(target, {
    get(obj, key, receiver) {
      onRead(key);
      return Reflect.get(obj, key, receiver);
    },
  });
}
```

## V8 Hidden Classes (Shapes) and Inline Caches — Under the Hood
An Inline Cache works like a keyed-entry warehouse dock: if every pallet arrives in the same box layout (Monomorphic), the forklift grabs slot #2 blindfolded; if five different box layouts arrive (Megamorphic), the worker stops to read the manifest hash table every time.

1. **Shape Transitions**: Creating `{ a: 1, b: 2 }` builds a shape chain `Empty -> +a (offset 0) -> +b (offset 1)`.
2. **Monomorphic Inline Cache**: At a call site `getX(obj)` inside a hot [Event Loop](/concepts/event-loop-tasks-microtasks) task, V8 caches the expected Shape and exact offset; a single pointer comparison suffices.
3. **Polymorphic vs Megamorphic**: Beyond 4 distinct Shapes at the same call site, the IC turns **megamorphic** and falls back to an expensive global hash lookup.

```js
// Monomorphic: both objects follow the exact same transition chain
function Point(x, y) {
  this.x = x;
  this.y = y;
}
const p1 = new Point(1, 2);
const p2 = new Point(3, 4);

// Megamorphic trap: different property orders create distinct Shapes
const bad = { y: 4, x: 3 };
```

## Interactive Labs & Dissections
- [Proxy Traps and Reflect Internals Lab](https://frontend.rocks/concepts/proxy-reflect-internals/#lab) ([Markdown](https://frontend.rocks/concepts/proxy-reflect-internals.md))
- [V8 Hidden Classes (Shapes) and Inline Caches Lab](https://frontend.rocks/concepts/v8-hidden-classes-ic/#lab) ([Markdown](https://frontend.rocks/concepts/v8-hidden-classes-ic.md))

## Primary Sources
- https://tc39.es/ecma262/#sec-proxy-object-internal-methods-and-internal-slots
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
- https://v8.dev/blog/fast-properties
- https://mathiasbynens.be/notes/shapes-ics
