Closed MarisaKirisame closed 6 years ago
It will calculate until it is eliminated by the garbage collector. The reason is that, otherwise, it would miss input event occurrences that came before the output was subscribed to. All functions that create state (i.e. monadhold functions) work this way.
On Jan 21, 2018 10:49 AM, "雾雨魔理沙" notifications@github.com wrote:
So suppose I created an computationally expensive event with foldDyn (so it is inside a monadwidget), and pass it into some user defined function. Now there is a good chance that the user defined function will ignore it and do nothing.
So basically, a event is register but never used.
Will it still be busy calculating? Or will it get optimized away?
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/reflex-frp/reflex/issues/160, or mute the thread https://github.com/notifications/unsubscribe-auth/ABGlYDua7wV54-0JhloGS04nnCWbo-fvks5tM1x-gaJpZM4Rl3Em .
When will it be eliminated though?
When the garbage collector runs, if there aren't any outstanding references to the state cell ('hold's), it will eliminate all the subscriptions from the events, which will stop the updating. Unfortunately, GC isn't super predictable, although you can trigger it manually.
One other thing to note: I don't think foldDyn will actually force each value, so even though the folding will continue, it may not actually do the work of your combining function until something needs it.
So let me repeat: foldDyn will eagerly push, but the value inside is still lazy, and is a thunk, so that expensive computation is not carry out.
Did I get it?
So suppose I created an computationally expensive event with foldDyn (so it is inside a monadwidget), and pass it into some user defined function. Now there is a good chance that the user defined function will ignore it and do nothing.
So basically, a event is registered but never used.
Will it still be busy calculating? Or will it get optimized away?