- Optimize
notifyListenersloop: Replacefor...ofwith index-based loop and add empty-check short-circuit. Implement Copy-on-Write (COW) for listeners to ensure safety during unsubscription without cloning on dispatch.- Actual: Switched to
Setwith COW strategy based on benchmark data (Set iteration ~10% faster than Array).
- Actual: Switched to
- Refactor to Class-based implementation: Replace closure-heavy
createStorewith aStoreImplclass to ensure monomorphic call sites and reduce memory pressure.- Expected Gain: 5-10% on raw throughput; better memory usage.
- Optimize
subscribeselector wrapper: Flatten the notification logic to reduce call stack depth during dispatch.- Expected Gain: 10-15% on "Update with Subscriber" benchmark.
- Eliminate
DeepReadonlyruntime overhead: Ensure casts are purely compile-time (verify no runtime impact remains).- Actual: Verified in
dist/store.jsandtypes.ts.DeepReadonlyis a mapped type with 0 runtime footprint.snapshot()returnsthis.currentdirectly.
- Actual: Verified in
- Final Benchmark: Compare against Redux and Zustand.
- Result: Exostate (17.5M ops/s) vs Zustand (13.4M ops/s) vs Redux (5.1M ops/s).
- Optimization: Using
Object.assignin reducer instead of spread ({...}) yields 2.5x speedup, beating Zustand by 30%.