Runtime Proxy Reactivity vs Static Compiler Graphs
Runtime reactivity intercepts reads and writes dynamically with Proxy and Reflect traps, tracking arbitrary nested objects at runtime. Static compiler reactivity parses AST assignments at build time to emit direct Fine-Grained Signals updates with zero proxy allocation.
Runtime Proxy Traps vs Compiled Updates
Compare how a runtime Proxy intercepts writes at execution time vs how a compiler emits direct updates.
Reading state.count inside an effect invokes the Proxy get trap and records a dependency.
get(target, key) { track(target, key); return Reflect.get(target, key); }- mode
- runtime-proxy
- proxyAllocations
- 1
- trackedKey
- count
Under the Hood
Both models eliminate full-tree Virtual DOM diffing, but they pay their tracking cost in completely different phases.
- Runtime Proxy Traps: Wrapping an object in
new Proxy(target, handler)allocates a proxy wrapper per nested object on access. Everygetpushes a dependency edge onto the active effect stack; everysetchecksObject.isand schedules subscribers. - Compiler AST Rewriting: A build-time compiler (Svelte, Solid JSX transform) statically analyzes component templates, converts reactive declarations into signal primitives or bitmask dirty checks, and emits direct
textContentmutations. - V8 Optimization Boundary: Proxy traps bypass V8 inline caches for dynamic shapes, whereas compiled signal reads compile down to monomorphic slot loads.
// Runtime Proxy: tracks any nested key read dynamically
const reactive = <T extends object>(obj: T): T =>
new Proxy(obj, {
get(target, key, recv) {
track(target, key);
return Reflect.get(target, key, recv);
},
set(target, key, val, recv) {
const ok = Reflect.set(target, key, val, recv);
if (ok) trigger(target, key);
return ok;
},
});Problem Genealogy
- 2013 (
Object.definePropertyWalkers): Vue 2 recursively walked every object key at startup, failing to detect added properties and burning 15–40 ms on large JSON tables. - 2020 (Lazy ES6
ProxyStores): Vue 3 and MobX switched to lazyProxywrapping, deferring wrapper allocation until nested objects are actually read. - 2023 (Hybrid Runes & Vapor Compilers): Frameworks combined fine-grained signal primitives with build-time template compilation to bypass proxy allocation in hot render paths.
Production Pitfalls
- Proxy Wrapping 10,000-Row Datasets: Passing large immutable API tables through deep
Proxywrappers allocates thousands of short-lived proxy objects and degrades scroll frame times. - Destructuring Breaks Tracking: Extracting
const { count } = stateoutside a tracked getter reads the primitive value once and severs futuregettrap subscriptions.
- When not to use deep runtime
Proxyreactivity: Never wrap large static datasets (GeoJSON, analytics grids, binary-backed buffers) in deep proxies; use shallow signals or mark objects non-reactive (markRaw/shallowRef).
Connections & Logical Next Steps
Runtime reactive stores intercept property reads and writes via ES6 Proxy get/set traps.
Both proxy stores and compiled reactivity build fine-grained dependency edges between state and DOM.