Let's talk Repeat nodes and how to avoid them

Discussions about SOFTIMAGEs© Interactive Creative Environment©
Chris_TC
Posts: 411
Joined: 22 Mar 2010, 16:43

Let's talk Repeat nodes and how to avoid them

Post by Chris_TC » 12 Jun 2011, 12:10

Let me preface by plugging this video, in which Stephen Blair shows how to build a grid without repeat nodes. Great technique! http://vimeo.com/22617674

I keep running into the issue of having to use repeat nodes in my trees. Everybody says they're bad, and indeed it seems they are pretty slow.
First of all, I'd like to know why they are so slow. Loops are used in regular programming all the time, aren't they? What's so bad about loops then?

Take the following example. I'm trying to use an array to drive a case node. For every array index the case should make a decision (build a cube or build a sphere). This works if I plug topo data into the Case node. But as soon as I want to use Execute data, this doesn't work anymore. The speed difference is ridiculous and cannot be explained away by better threading. The repeat node takes 18 times as long on my system. That's a quad-core machine, not an 18-core machine.

Image
Image

User avatar
owei
Administrator
Posts: 840
Joined: 03 Jun 2009, 15:25
Location: Siegen/Germany

Re: Let's talk Repeat nodes and how to avoid them

Post by owei » 12 Jun 2011, 14:27

Hi!
The "problem" with the case-node is, that it only accepts ONE value per object/point/whatever. To get this to work, you might use the "pop from array" and set the new values for the new array again. So you will fetch only one value per object/point/whatever but also step through the whole array. This should do the job...

best,
oliver

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 16:43

Re: Let's talk Repeat nodes and how to avoid them

Post by Chris_TC » 12 Jun 2011, 15:06

Hi Oliver,
I'm not sure I'm following you. If I pop the last value and set the new array, will I not need a repeat node to do this?

User avatar
owei
Administrator
Posts: 840
Joined: 03 Jun 2009, 15:25
Location: Siegen/Germany

Re: Let's talk Repeat nodes and how to avoid them

Post by owei » 12 Jun 2011, 15:11

...if you set the new array with the "result" output, it should be OK ;)

best,
oliver

User avatar
Mathaeus
Posts: 1778
Joined: 08 Jun 2009, 19:11
Location: Zagreb, Croatia

Re: Let's talk Repeat nodes and how to avoid them

Post by Mathaeus » 12 Jun 2011, 15:56

Hi there,

I'm not sure does this helps, but anyway, here's what I'm using for point mini crowds based on ICE Point Clouds, where each particle is a body part - with this one I'm able to set point position to all left foots in crowd, for example. Firstly I've used 'select case', but the one from picture is faster in complex setup. I've read on SI mail list that 'Select Case', internally is a some kind of if-else chain, so probably isn't so fast with many inputs.

As for repeat node, well, I have no idea how it can be replaced in cases, when each member needs to take the summary of previous members, for example. Sometimes it's possible to calculate the math 'in advance'. Sometimes you'll be able to live with limited number of inputs, and just create a boring but efficient, 'fixed' node (just as mix8colors node in rendertree). Sometimes.... repeat node is your destiny :)

btw, great work on city building !

Image

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 16:43

Re: Let's talk Repeat nodes and how to avoid them

Post by Chris_TC » 12 Jun 2011, 18:57

owei wrote:...if you set the new array with the "result" output, it should be OK ;)
But the Select Case evaluates only once. It picks the popped value, then executes whatever is plugged into the matching case, and that's it. Even if you update the array, the Select Case will not loop through again using the new array.

@Mathaeus: If I understand this right you're creating a custom per-point attribute and making the decision based on that. Looks like a very useful technique for situations with a per-element context. I think I need object context, but I'll definitely play with the idea.

grahamef
Posts: 281
Joined: 23 Jun 2009, 19:01

Re: Let's talk Repeat nodes and how to avoid them

Post by grahamef » 13 Jun 2011, 19:27

As I understand it (and remember that I'm not a developer), one of the reasons that Repeat is slow is that it needs to wait for all threads to finish and sync up before it can begin another iteration. There may be other issues too. You can speed things up a bit by using a fixed number of iterations, e.g., 3 instead of Get Array Size.

The reason that the second tree does not work is that you cannot have an array of executes. "Execute" isn't really a data type.

If you want each case to do more than just create a topo, you can use multiple Select Case nodes with the same Condition input.

Chris_TC
Posts: 411
Joined: 22 Mar 2010, 16:43

Re: Let's talk Repeat nodes and how to avoid them

Post by Chris_TC » 13 Jun 2011, 19:41

grahamef wrote:If you want each case to do more than just create a topo, you can use multiple Select Case nodes with the same Condition input.
Yes, that's what I ended up doing. The manual specifically mentions that Set Topology is very slow and should not be used within repeat nodes if it can be avoided.
So I'm now using multiple Case nodes, and performance is much better because the Set Topology is called only once.