MoonBit implementation of classic adapton
Classic adapton features:
- Laziness
setdoes not update immediately, but marks the corresponding dependency graph nodes asDirtygetonly updates dependency targets when the dependency source actually changes
- Dependency graph
- When the source actually changes,
dirtymarks nodes that need updating asDirty - When the target is accessed,
propagatecallsupdateon nodes that need updating and marks them asClean Thunk::getautomatically builds the dependency graph on first call, with a globaltarget_stackvariable to help with construction
- When the source actually changes,
- Memoization
- The memo part here refers to DCG (Demanded Computation Graph) nodes
For most scenarios, using the laziness and dependency graph parts is sufficient.
Spreadsheets do need memoization quite a bit. Memoization is designed to solve the problem of dynamic dependency graphs. GUI application dependency graphs are generally static and relatively small - this is a matter of granularity control.
Adapton itself is also pure functional programming. Thunk[Unit] will cause computations that depend on it to never update, so you need to write Thunk[State] that always returns the next state to trigger corresponding actions.
Because MoonBit currently lacks WeakRef, WeakMap, WeakSet, WeakArray, memory leaks will occur, and this becomes more severe when using memoization.
Incremental computation itself is also quite memory-intensive.
-
illusory0x0/adapton.ocaml This repository changes the build system to use
duneand fixes some bugs where deprecated OCaml APIs prevented compilation. -
Adapton: Composable, demand-driven incremental computation, PLDI 2014 The
dirty&propagatealgorithm used in adapton.mbt is adapted from here