Crescent-Team / Potok

A modern reactive library for Luau.
0 stars 0 forks source link

Explore a new execution model #1

Open xiyler opened 4 months ago

xiyler commented 4 months ago

Currently, we need to explore a new execution model to provide a set of guarantees that we desire. While the current, eager-based one provides the fundamental ones such as skipping updates if there is no meaningful change and updating the tree in the correct order, there are various features the current model fails to deliver.

The guarantees are the following:

xiyler commented 4 months ago

The push-pull execution that Fusion is adopting, makes lazy computation easy and enables topological sorting a property in the behavior in the model rather than an explicit mechanism, however, it complicates other parts, such as skipping updates, and releasing values.

A lazy-based model is still desired, however the push-pull model complicates other various stuff, and additionally has the potential to lower performance and increase memory usage. While we can cut some slack for Fusion, it's unlikely to do so for Potok as it's intended use is to implement game features based on the idea of reactive programming. As such, performance and general memory usage should be kept in consideration in designing every bit of the library.

xiyler commented 4 months ago

Specifically speaking, the push-pull model requires us to store the dependencies and dependents of each object, hence the increase in memory usage.

Looking at other lazy-based libraries outside of the Luau ecosystem could be beneficial too.

xiyler commented 4 months ago

Perhaps a way to model this lazy execution is to find a way to mark parts of a tree as side effectual, as in, it's observed through effects or some internal function, so when we update the tree, we could skip the unneeded nodes.

However, what would we do when we evaluate a node outside of an update process? Part of the evaluation process is skipping unnecessary updates, and while this easy during an update process, it becomes complicated outside of a process.