Multiple node output links == multiple executions?

Hey, I’m still not sure how it works:

As you can see on the image. In this case, is the multiply node (and everything linked to it before) executed twice? If so, then from optimization perspective it’s better to save this to a local variable and then reuse it - so this way it would execute only once, and then access already calculated value from local variable.

… But maybe there is some automatic optimization happening already? Has anybody have an idea on how this works? Cheers!

Hey Slavq,

From what I can tell from your graph I believe you should only be executing it once.

I can’t remember where the flow explanation was but from memory it works something like this:

Once an execution node is called it started from the calculation furthest back and than calculates forward. So the multiplication is called only once.

Below is an example of when it would have to calculate it twice:

In this example, because the section commented in purple is begin called by the red and blue execution function/macros, they will run their calculations twice.

Where as the float x 2 calculations that are commented in blue only get called once because they are only called by the section function/macro also highlighted in blue.

Below I’ve tried to highlight the flow, where you will see the first calculations are highlighted twice:

][3]

Long answer short: Yes it is executed twice.

In their last livestream getting started with code or something like that, they talked about pure functions and this.

If you want it to be only calculated once you have to store it in a variable.

According to @Miroac answer, it’d be executed only once though…? (if I understand it correctly) Thanks!

Thank you! But if I understand correctly, we have two contradicting answers right here… ? :slight_smile: ( @anonymous_user_f61a7ed1 answer )

If you have a node without execution pin, the code that is connected to that node will fire the amount of times you connected its output to other nodes. To prevent it from executing multiple times you have to promote the output to a variabele.

may be correct on this one. I was referencing a source from a while back that I cannot find to verify.

OK, thank you both for the answers!

Actually, in the first example all pins lead to the same node with execution pins while the second example there are two nodes with execution pins. He means that no matter how many inputs the node has, all the pure and const nodes for that one node could be cached and executed only once but as soon as you go through an execution pin the answers are clean and calculated again for the next node.