raquo / Airstream

State propagation and event streams with mandatory ownership and no glitches
MIT License
247 stars 28 forks source link

Sampling a signal shouldn't cause the overhead of observers #88

Closed raquo closed 1 year ago

raquo commented 3 years ago

Currently we add empty / noop observers to keep the sampled signal started. That's fine, but it inflates the array of the sampled signal's observers for no reason. Since these noop observers have no payload, we could instead increment / decrement a noopObservers counter. We'll need to provide public noop Observer and InternalObserver instances to compare against when adding an observer, and make sure to use them.

This will cost us one Javascipt Number (64-bit) per every observable. Well, maybe we make it js.UndefOr[Int] to avoid that.

Anyway, just a small perf improvement for certain uses, for when I'm in the mood.

raquo commented 1 year ago

Closing because I'd rather keep it simple for now.