Skip to content

Feature/improve performance#26

Merged
hexplus merged 29 commits into
mainfrom
feature/improve-performance
Apr 19, 2026
Merged

Feature/improve performance#26
hexplus merged 29 commits into
mainfrom
feature/improve-performance

Conversation

@hexplus
Copy link
Copy Markdown
Owner

@hexplus hexplus commented Apr 19, 2026

Description

Rewrites the reactivity core subscription graph for performance.

  • Doubly-linked SubNode edges replace the previous Set<Subscriber> + Map<Signal, epoch> storage. Each (signal, subscriber) pair is now one object linked into both the signal's subscriber list and the subscriber's dep list. O(1) subscribe and unsubscribe via pointer splice, no hash operations on the hot path, one allocation per edge instead of two.
  • signal.__activeNode back-pointer (Preact Signals' approach) gives recordDependency() O(1) duplicate-dependency detection. A subscriber with 10 000 deps no longer pays O(N²) in its inner loop.
  • Effects now re-run via retrack() instead of track(). Stable-dep effects skip the full cleanup-and-rebuild cycle; epoch-based pruning handles dropped deps.
  • Effect internals consolidated behind an EffectCtx object — per-effect closure count went from six to three.
  • track() is stack-free — local prev/restore replaces the shared subscriberStack. suspend/resumeTracking now capture currentSubscriber directly.
  • Signal state pre-initialises every internal slot + setter specialised at creation time + cached disposer + node pool (cap 4 096) → monomorphic hidden classes and dramatically reduced GC churn on create/destroy workloads.
  • New exports: cleanup, getSubscriberCount, getSubscriberDeps, forEachSubscriber.
  • Removed internal __s, __f, subscriberStack (all undocumented, underscore-prefixed).

Improvements over 2.1.0 on the reactivity stress-test suite:

  • Wide graph / 10k fan-out: ~73% faster (56.8 ms → 15.4 ms)
  • Cascading effects: ~41% faster (2.03 ms → 1.20 ms)
  • Memory & cleanup: ~21% faster (51.3 ms → 40.6 ms)
  • Component tree: ~10% faster
  • Deep computed chain: ~7% faster

2187/2187 tests passing. No breaking changes to the documented public API (signal, derived, effect, batch, untracked, on, devtools helpers — all behave identically).

Related Issue

Closes #

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Checklist

  • I have read CONTRIBUTING.md
  • My code builds without errors
  • I have tested my changes
  • I have updated documentation if needed

hexplus added 29 commits March 28, 2026 15:11
@hexplus hexplus merged commit af9a0f2 into main Apr 19, 2026
1 check passed
@hexplus hexplus deleted the feature/improve-performance branch April 19, 2026 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant