Signal Internals (O(1) Engine)
Quantum Query is built on top of a "Micro-Signal" architecture. This is what enables its "9.2/10" senior-rated performance.
The Core Primitive: Signal<T>
Unlike React's useState, which is bound to a specific component's lifecycle and re-render cycle, a Signal is an independent reactive value.
- Storage: Signals live in the
QueryStorage(a specialized LRU Cache). - Reactivity: We use
@preact/signals-corefor the underlying delivery mechanism. - Reference Stability: Every query key is mapped to a singleton signal instance.
Why O(1)?
In a subscription-based model (like TanStack Query), when data changes:
- The library iterates through a list of observers.
- Each observer checks if it's still mounted.
- Each observer triggers a React state update.
- React reconciles the tree.
In Quantum's Fine-Grained model:
- The signal value is updated.
- The signal notifies its direct dependencies (the DOM nodes or hooks using the value).
- Only the specific parts of the UI that depend on the changed field are updated.
Memoization & Stability
The QueryObserver uses a sophisticated computed block to derive the result object.
this.result$ = computed(() => {
const entry = cacheSignal.get();
// ... derive isLoading, isStale, etc.
if (isDeepEqual(lastResult, nextResult)) {
return lastResult; // Reference stability!
}
return nextResult;
});
This ensures that even if a signal "pings", your React component only re-renders if the meaningful data has changed. We call this "Reference Transparency".
Garbage Collection (GC)
Signals are smart. They know when they are being watched.
- onActive: When the first component subscribes, the signal cancels any pending GC timer.
- onInactive: When the last component unmounts, the signal schedules a GC based on
cacheTime. - Automatic Cleanup: If the signal is never watched again, it is purged from memory, including any internal timers.