Skip to content

perf(core): eliminate backing state allocation in derive and select#109

Merged
nerdalytics merged 1 commit into
trunkfrom
perf/73-reduce-derive-select-allocations
Apr 6, 2026
Merged

perf(core): eliminate backing state allocation in derive and select#109
nerdalytics merged 1 commit into
trunkfrom
perf/73-reduce-derive-select-allocations

Conversation

@nerdalytics
Copy link
Copy Markdown
Owner

Closes #73

Summary

  • Replace internal createState in createDerive and createSelect with a direct value slot and a Set<Subscriber> for downstream tracking
  • Eliminates one full state allocation (subscribers Set, stateId Symbol, closures) per derive/select instance
  • Removes unnecessary notification cycle on first lazy read (no external subscriber can exist yet)
  • Subscriber registration and cleanup still works correctly via subscriberDependencies

Benchmark

10k signal allocation:

Before (min) After (min) Change
derive allocation 20.674ms 15.348ms -26%
select allocation 20.862ms 17.645ms -15%
derive chain propagation 1.489ms 1.506ms neutral

Test plan

  • Biome lint passes
  • TypeScript compiles with no errors
  • All 117 tests pass
  • Benchmarked before/after

)

Replace the internal createState in createDerive and createSelect with
a direct value slot and a subscribers Set for downstream tracking. This
halves the per-signal memory footprint by removing one full state
allocation (subscribers Set, stateId Symbol, closures) per instance.

Also eliminates the unnecessary notification cycle on first lazy read,
since no external subscriber can exist yet at that point.

Benchmarked: ~26% faster derive allocation, ~15% faster select
allocation (10k signals).
@nerdalytics nerdalytics merged commit a021cd1 into trunk Apr 6, 2026
12 checks passed
@nerdalytics nerdalytics deleted the perf/73-reduce-derive-select-allocations branch April 6, 2026 18:18
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.

core: double allocation per derive and select instance

1 participant