Closed twop closed 2 years ago
Not sure if it is on your radar, but https://fsprojects.github.io/FSharp.Data.Adaptive/ may offer some inspiration.
See also https://github.com/krauthaufen/Fable.Elmish.Adaptive, https://github.com/dsyme/fabulous-adaptive, and https://www.youtube.com/watch?v=mZ3o6TqNR6U .
Problem
Currently we calculate diff recursively for the entire tree all at once. As a part of it we use a recursive data structure
There a a couple of concerns here:
ApplyDiff
they immediately become garbage applying pressure on GC.Idea to explore
Make calculation of children diff somehow lazy. Note that it potentially ok to have dynamic dispatch (virtual call) if it removes allocations. I haven't researched enough the new feature of "Resumable Code" in F# 6, to understand if that idea is even applicable to us.
But roughly it would be awesome if we can somehow express this (pseudo code):
My intuition tells me that in this form
LazyCollection
has to be dynamically allocated, thus it is probably not better than status quo.HOWEVER this is probably an opportunity to express the same recursive Diff via some other data structure. Like so
Where the
Stream
data structure might be "Resumable Code". If so then we can replace[]
withStackArray
(stack allocated collection), thus avoiding intermediate allocations. Not sure if it is possible to avoid dynamic dispatch though.Objective
Research what are the options making diff calculation lazy, and have a PoC ideally backed by benchmark how it might work.
Note that it is probably going to be one of the last perf explorations (at least according to my intuition), because other "[Performance]" tasks probably have more predictable ROI.