TimLariviere / Fabulous-new

Fabulous v2 - Work in progress
https://timothelariviere.com/Fabulous-new/
Other
41 stars 3 forks source link

Incremental Diffing? #55

Closed NatElkins closed 2 years ago

NatElkins commented 2 years ago

Hi,

I’ve been casually following the development of Fabulous V2. Awesome work, really impressive stuff. I was just taking a look at the changes in diffing, and I wanted to put something on your radar, and was wondering if it had been considered. From a brief skim of the code, it kind of looks like each control is wrapped in a kind of builder (WidgetBuidler, CollectionBuilder, etc) that is responsible for being able to calculate the different types of things that could’ve changed (ScalarAttribute, WidgetAttribute, etc). And then the diffing basically takes two Widgets, and then diffs the attributes.

One thing I was thinking about is whether something like https://fsprojects.github.io/FSharp.Data.Adaptive/ could be useful for this. The rough outline of how I was thinking it would work is that each control could have an “adaptive” version generated via https://github.com/krauthaufen/Adaptify/, and then the Fabulous DSL would be responsible for updating values via the FSharp.Data.Adaptive API (transact function). The user-facing API/DSL could stay the same as it is now. And then when the program would want to diff, it would be able to get a near-perfect incremental re-computation of whatever you would want to recompute. Unfortunately, this would be a somewhat intrusive change at the moment, since this would change how the actual data about diffs would be stored (rather than simply changing the diffing algorithm). But I figured I would mention it now while there's still a lot of things in flux.

Anyway, food for thought.

TimLariviere commented 2 years ago

Hi!

Thanks for mentioning this. When FSharp.Data.Adaptive was first created, I thought it was using some kind of reactive mechanism like Comet is doing. Wanted to dive into it but never found time.

I'll take a closer look, play with it a little. See what it brings and what it would mean for Fabulous.

I know Don created a fork of Fabulous some time ago using it: https://github.com/dsyme/fabulous-adaptive

Though I must admit, there is a rather low chance we'll use it in Fabulous v2.

twop commented 2 years ago

Hey @NatElkins , the closest (spirituallu) project I know that is using incremental diffing is IncrDom from JaneStreet. https://opensource.janestreet.com/incr_dom/

A good walkthrough of the approach there: https://www.youtube.com/watch?v=h_e5pPKI0K4&t=3977s

They recently moved away from the approach because it was too complex, thus was painful to use internally. More info in this podcast: https://signalsandthreads.com/building-a-ui-framework/

So in short: I believe there is a place for incremental computation in UI frameworks, but I don't know of a good example of that yet.

Although, I have a feeling that this approach can be built on top of Fabulous v2 using Memo. If it is possible I would love to have this idea implemented as a 3rd party library.

NatElkins commented 2 years ago

Thanks all for getting back to me. I will close this issue for now as if it does get integrated, it sounds like it will be more likely done as a library.