-
Notifications
You must be signed in to change notification settings - Fork 24
Description
I'd hope to have recomputations use cached values when inputs are the same! I think it is not the case currently...
Here is an example. Hopefully, it's copy-pastable in utop so you can test.
I have a int var representing time:
let time = Lwd.var 0And a computation that is "costly" but will only change if time is not too big.
let max_time = 1000
let big_list = List.init max_time Fun.id
let compute time =
Format.printf "Let's go with a costly computation with time = %d\n" time;
List.filter ((>=) time) big_listI though Lwd would cache the result and avoid the recomputation in the following:
let l =
let$* very_big =
let$ time = Lwd.get time in
time >= max_time
in
if very_big then
Lwd.return @@ compute max_time
else
let$ time = Lwd.get time in
compute timeWhen time changes, the very_big value may not change (from true to true) but compute max_time is still done, as seen by the log...
> let root = Lwd.observe l
> let () = Lwd.set time (max_time + 1)
> let sample1 = Lwd.quick_sample root
Let's go with a costly computation with time = 1000
> let () = Lwd.set time (max_time + 2)
> let sample2 = Lwd.quick_sample root
Let's go with a costly computation with time = 1000I'd really like the second sample to not recompute after getting very_big unchanged, and thus not show the second "Let's go with a costly computation with time = 1000"!
I'd be happy to help in fixing this issue, but I would also appreciate some help to get started 🙂