In a previous post incremental
was suggested to organize computations so that they’d be “as lazy and deferred as possible”.
As I understand it, incremental
does not update immediately after a change in input variables, and waits for a call to stabilize
before doing the calculation, and in doing so, it will refrain from updating nodes that are not useful to compute observed values.
I have a use case where I want to build a large number of computations, and repeatedly observe a tiny but changing subset of them after a variable modification (at each iteration I change a different variable). I’m basically considering to use the following function:
let eval x =
let o = Inc.observe x in
Inc.stabilize () ;
let y = Inc.Observer.value_exn o in
Inc.Observer.disallow_future_use o ;
y
and then repeatedly call Var.set
and eval
on different pairs of variable and computation. I don’t know incremental
very well, so I’d like to know if this would be a severe misuse of the library and if there is a better way to achieve “as lazy and deferred as possible” computations when both modified and observed nodes of the computation graph change at each query.