Sun Apr 18 20:21:43 EDT 2010
Reactive Dataflow & GC
Is it possible to have intermediate values disappear when all their
dependencies have read the value?
This is PDP! Funny.. Went full circle there ;)
How do the computation thunks reference the reactive values?
(define (rv-apply fn parents)
(apply fn (map rv-force parents)))))
(for ((p parents))
(rv-register-child! p node))
Esentially through `parents' in the `rv-apply' function. The thunk is
the expression in the `rv-delay' form.
The right question seems to be: Is it possible to let go of the value
reference to the parent nodes value slot, but keep track of the node
references? I.e. keep the connectivity alive, but only keep values as
long as they are needed.
A possible answer could be to keep a semaphore as a reference count:
every time a node is created, initialize the semaphore to the number
of clients the node has. On each read of the node through an
rv-apply, decrement the semaphore. When zero, delete the node.
It feels a bit ad-hoc to do that though.. Also I can't really see
whether that introduces problems elsewhere..
Edit: it's indeed not that simple. Supoose we have a value y = a + b,
and a gets invalidated, invalidating y. When y gets pulled, a is
recomputed, but b is pulled from the cache. Point being: even if
there is only a single dependency b -> y, the value of b, it might
still be useful to keep b around after y is computed.