5 ms·
Overall, very nice article. A few notes: * I think the first implementation in JS land was Flapjax, which was around 2008: https://www.flapjax-lang.org/publica
by noelwelsh 6mo ago
Overall, very nice article. A few notes:
* I think the first implementation in JS land was Flapjax, which was around 2008: https://www.flapjax-lang.org/publications/ https://www.flapjax-lang.org/publications/
* The article didn't discuss glitch-freedom, which I think is fairly important.
- HumanOstrich 6mo agoAfter wondering what the heck glitch-freedom is and learning about it, I agree with you. It seems like it deserves at least a brief explanation in an article about how signals work. I've gone with the universal `alien-signals` package for my project (which doesn't use a frontend framework that includes signals). They show benchmarks of being by far the fastest and have strict limits on code complexity. Those limits are also supposed to avoid glitches by design, and now at least some of that is tested[1]. [1]: https://github.com/stackblitz/alien-signals/pull/39 https://github.com/stackblitz/alien-signals/pull/39
- willybrauner 6mo agoI didn't know about Flapjax, thanks I'll check it out. Glitch-freedom is indeed a gap in this article. I focused on the signal algorithm exclusively without some implementation optimisation like batching updates; there is so much more to cover! Maybe in a next one, Thanks!
- mpweiher 6mo agoAnd before there was "reactive", there were (oneway) dataflow constraints. And a lot of literature on the algorithms. I wrote a bit about the connection here: https://blog.metaobject.com/2014/03/the-siren-call-of-kvo-and-cocoa-bindings.html https://blog.metaobject.com/2014/03/the-siren-call-of-kvo-an... (It starts in a slightly different place, but gets there) Also about constraints as an architectural connector. https://dl.acm.org/doi/10.1145/2889443.2889456?cid=81316491227 https://dl.acm.org/doi/10.1145/2889443.2889456?cid=813164912...
- pygy_ 6mo agoBatching isn't just an optimisation, not having transactional semantics can cause bugs.
- mananaysiempre 6mo agoI wrote a whole screed here about how glitches are evil and Rx is evil for teaching people they’re normal, but then I thought about it a bit more— The system as described isn’t actually glitchy, is it? It doesn’t eagerly run any user computations, just dirtying, and that is idempotent so the order is irrelevant. It’s also a bit useless because it only allows you to pull out values of your own initiative, not subscribe to them, but that’s fixable by notifying all subscribers after the dirtying is done, which can’t cause glitches (unless the subscribers violate the rules of the game by triggering more signals). So now I’m confused whether all the fiddly priority-queue needlepoint is actually needed for anything but the ability to avoid recomputation when an intermediate node decides it doesn’t want to change its output despite a change in one of its inputs. I remember the priority queue being one of the biggest performance killers in Sodium, so that can’t be it, right?.. I’m also confused about whether push-pull as TFA understands it has much to do with Conal Elliott’s definition. I don’t think it does? I feel like I need to reread the paper again. Also also, some mention of weak references would probably be warranted.
- mpweiher 6mo ago> whether push-pull as TFA understands it has much to do with Conal Elliott’s definition. Virtually nothing that is getting sold/branded as "FRP" has anything to do with Conal Eliott's definition. I once gave a long talk about this here in Berlin, but I don't remember if there was a video. I've also explained it on twitter a bunch of times, including this memorable sequence: https://x.com/mpweiher/status/1353716926325915648 https://x.com/mpweiher/status/1353716926325915648 Kinda like the Marshall McLuhan scene in Annie Hall ("if only real life were like this") https://www.youtube.com/watch?t=136&v=sXJ8tKRlW3E https://www.youtube.com/watch?t=136&v=sXJ8tKRlW3E
- mananaysiempre 6mo ago>> whether push-pull as TFA understands it has much to do with Conal Elliott’s definition. > Virtually nothing that is getting sold/branded as "FRP" has anything to do with Conal Eliott's definition. True but not what I meant. The article implicitly (and, in the links at the end, explicitly) refers to his 2009 paper “Push-pull functional reactive programming”, which describes a semantic model together with an specific implementation strategy. So I was wondering if TFA’s “push-pull” has anything to do with Elliott 2009’s “push-pull”. I don’t think so, because I remember the latter doing wholly push-based recomputation of discrete reactive entities (Events and Reactives) and pull-based only for continuous entities that require eventual sampling (Behaviors). With that said, I find it difficult to squeeze an actual algorithm out of Elliott’s high-level, semantics-oriented discussion, and usually realize that I misunderstood or misremembered something whenever I reread that paper (every few years). So if the author went all the way to reference this specific work out of all the FRP literature, I’m willing to believe that they are implying some sort of link that I’m not seeing. I would just like to know where it is.
- xkbear89 6mo ago[flagged]
- boxfire 6mo agoSo yeah topological sorting is one element, but that global stack is a data race! You need to test set inclusion AND insert into it in an ordered way. Global mutex is gross. To do so lock-free could maybe be done with a lock free concurrent priority queue with a pair of monatomic generation counters for the priorities processed then next, then some memo of updates so that the conflicting re-update is invalidated by violation the generation constraint. I see no less than 3 CAS, so updates across a highly contentious system get fairly hairy. But still, a naive approach is good enough for the 99% so let there be glitches!
- deleted 6mo ago[deleted]
- aatd86 6mo agoCan the reactive graph even be updated concurrently if the UI depends on it though? Because the UI is likely to run in its own single thread...
- Groxx 6mo agoyea, this is in javascript. it's inherently single-threaded in almost all contexts (e.g. node.js shared memory where you're intentionally bypassing core semantics for performance, and correctness is entirely on you)
- Groxx 6mo agowouldn't this be solved by synchronously invalidating everything before computing anything? it seems like that's what the described system is doing tbh, since `setValue` does a depth-first traversal before returning. or is there a gap where that strategy fails you?