We're currently using Rete's built-in Dataflow Engine, which works for the most part, but in our specific case there's some optimizations we can make and features we could add.
The issue
The Dataflow engine (source code here) is recursive: it starts from the output nodes and recursively retrieves the inputs and evaluates them, because it's possible for a general application to need the inputs in order to construct the output.
This is fine, but it also means that loops in node setups don't work. With the Dataflow engine, any nodes involved in a loop are simply not evaluated at all in order to avoid crashing the browser.
Additionally, there may be some optimizations we can make with our own custom engine to avoid deleting and recreating every node every time the graph is reevaluated.
Why we (maybe) don't need recursion
Our nodes technically can, for the most part, be constructed without any knowledge of the inputs and then have their connections and values set later. Therefore, we generally don't need to do any recursion, and we can instead split our evaluation into two iterative steps.
Iterate through all nodes and create their corresponding AudioNodes. (If the node has a base value that doesn't come from a connection, and instead comes from an input field, we can initialize these here too.)
Iterate through all nodes and connect their AudioNodes to their appropriate destination AudioNodes.
The snags
There's a few gotchas in the code's present state that introduce some challenges.
When it comes to bundled inputs, we do actually need the input in order to figure out how many nodes to create. For example, a 2-width bundle going into an oscillator node would require two OscillatorNodes to be created instead of just one, but we can't know what the bundle width is before we do any evaluation. Maybe it's worth sacrificing bundling to make loops work?
EDIT 1/31/24: Bundling has been removed so this is no longer a concern! All nodes now don't care about their inputs for construction of their underlying AudioNodes, so steps 1 and 2 from before can run sequentially.
We'll need to engineer this a bit before we start working on it.
We're currently using Rete's built-in Dataflow Engine, which works for the most part, but in our specific case there's some optimizations we can make and features we could add.
The issue
The Dataflow engine (source code here) is recursive: it starts from the output nodes and recursively retrieves the inputs and evaluates them, because it's possible for a general application to need the inputs in order to construct the output.
This is fine, but it also means that loops in node setups don't work. With the Dataflow engine, any nodes involved in a loop are simply not evaluated at all in order to avoid crashing the browser.
Additionally, there may be some optimizations we can make with our own custom engine to avoid deleting and recreating every node every time the graph is reevaluated.
Why we (maybe) don't need recursion
Our nodes technically can, for the most part, be constructed without any knowledge of the inputs and then have their connections and values set later. Therefore, we generally don't need to do any recursion, and we can instead split our evaluation into two iterative steps.
The snags
There's a few gotchas in the code's present state that introduce some challenges.
We'll need to engineer this a bit before we start working on it.