snakster / cpp.react

C++React: A reactive programming library for C++11.
http://snakster.github.io/cpp.react/
Boost Software License 1.0
1.02k stars 128 forks source link

Is lazy node supported? #7

Closed jamboree closed 9 years ago

jamboree commented 9 years ago

In the paper "Deprecating the Observer Pattern with Scala.React" there's a section "Strict vs Lazy Nodes", quoting from the paper:

Lazy nodes are notified by their dependencies eagerly, but validated only when queried

My simple test showed that C++React evaluates the nodes when notified even though no one queries. Is lazy node implemented? If not, is there any plan? or is it impossible for C++React?

schlangster commented 9 years ago

As you observed, lazy evaluation is not implemented. I gave it some thought in the past, but I concluded that the costs would outweigh the benefits. More specifically, I was considering signals, where it's possible to access their current value imperatively. If that access were to trigger cascading re-evaluations, that would introduce the need for additional synchronization.

What would be an interesting optimization for events (though not quite the same as "lazy") is marking subgraphs that currently don't have any consumers (signals, observers) attached, so that they could be skipped.

jamboree commented 9 years ago

Thanks for your reply. I learned of FRP recently and am quite interested in applying such paradigm to image processing, so in my case the processing nodes would be image filters which may be expensive to compute, but still I'd like to construct the whole dependencies among the filters beforehand, so the laziness is of more importance here.

FWIW, I stumbled through some FRP libs in C++, including Sodium, RxCpp, sfrp, and your lib looks quite promising and best documented, though I probably can't use your lib for the reason above.

Anyway, you've done a good job and good luck to your lib!