I often have a situation where certain code parts don't really need to be recalcuated, because their inputs have not changed from an earlier encounter.
For example if a function is the sum of two different complicated and slow calculations where each of the two depend on a different subset of parameters, often only one needs to be recalculated, while the other intermediary result could be grabbed from a cached value. (This occurs for example during the calcuation of partial derivatives).
In some cases, the compiler could probably recognize these situations, but I think we should have a special structure to allow caching of intermediary results.
I typically use a case structure and two feedback nodes as shown in the example on the left. If the value is different, the code in the TRUE case is executed, else the value stored in the SR is returned immediately. (If the code depends on several values, I bundle them all before the comparison operation)
I propose an simple Caching Structure as show on the right that retains that same functionality with less baggage.
Details: The containing code is calculated at first run and stored in the output tunnel. In later calls, it is either (A) recalculated, or (B) the previously stored value returned at the output tunnels. Recalculation only occurs under some conditions (.i.e. usually when actually needed)
The structure has the following features:
There can be an unlimited number of input and output tunnels of any type described above. A recalculation of the inner code occurs if any of the triggering tunnels have a changed value.
We can think of it similar to "short-term folding".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.