WebAudio-Node-Editor / webaudio-node-editor

1 stars 0 forks source link

Engine rewrite #23

Open ruan-xian opened 9 months ago

ruan-xian commented 9 months ago

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.

  1. 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.)
  2. 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.

We'll need to engineer this a bit before we start working on it.

santolucito commented 9 months ago

This also partially solves #4