2
$\begingroup$

I am working on scientific visualizations involving huge arrays of 3d vectors, sometimes 100k or sometimes even millions of vectors. I quickly ran into performance related issues, mostly when needing to iterate over arrays of vectors, or even values, using Loop Inputs. Case in point, the attached blend file, that "spiralizes" a linear segment. I generate an 1D array of numpy values between a and b using:

interpolated_values = np.linspace(value_a,value_b,number_of_elements)

and I invoke that in a 3d vector combine node in x and rotate every vector in the array around it's Z-axis using a multiplied value of it's own index. In order to do that I have to iterate over the array using a Loop Input node. So far so good, it works, but the performance is a killer. Already by 1k iterations the scene lags like crazy on a quite powerful machine. Comparatively, if I do exactly the same in XSI's ICE, I can generate over 100k vectors before the scene starts lagging. Is there a better way to achieve this than using Loop Input, which is the culprit here? Using a for loop in Python doesn't work of course, as the for loop is first executed in the script and then called in AN... Here is the attached blend file https://we.tl/t-L8snsm1VOE

$\endgroup$
4
  • $\begingroup$ I am not sure how familiar you are with AN and autoexecution? Do you know what autoexecution does? If not, you should think about using triggers...docs.animation-nodes.com/documentation/introduction/execution $\endgroup$
    – Chris
    May 5, 2021 at 2:41
  • $\begingroup$ Thank you for your answer Chris, but that doesn't really solve the lag, it just delays it until the code gets executed. I mean, it doesn't bring anything to improve the performance, if I have to wait 20 minutes for the code to iterate over a 100k by any change of value or some kind of other trigger. $\endgroup$
    – radoo
    May 5, 2021 at 8:10
  • $\begingroup$ well...this wan't an answer - it was a comment ;) $\endgroup$
    – Chris
    May 5, 2021 at 8:16
  • $\begingroup$ thank you for your comment :) $\endgroup$
    – radoo
    May 5, 2021 at 8:19

2 Answers 2

1
$\begingroup$

I think it is executing the script node every iteration so I added a float list parameter to the loop and put your script node outside of the loop. On my machine instead of about 350ms execution time I got about 50ms execution time with it outside. about 7 times improvement. enter image description here

$\endgroup$
5
  • $\begingroup$ Something like this I had in my mind - but radoo „knew“ better ;) well done! $\endgroup$
    – Chris
    May 6, 2021 at 2:33
  • $\begingroup$ Hi Richard, thank you! That's awesome! $\endgroup$
    – radoo
    May 6, 2021 at 13:27
  • $\begingroup$ Jesus, Chris, :D How is your comment about autoexec and triggers having anything to do with Richard's solution? $\endgroup$
    – radoo
    May 6, 2021 at 13:30
  • $\begingroup$ Hi radoo, would you be able to mark the question as answered, please? Also there is a you tube channel called "Thinking Penguin" who does stuff on animation nodes. He has a video called "Speed Up Performance in Animation Nodes by Caching" which I think you will find useful for your sort projects with large arrays. $\endgroup$ May 6, 2021 at 18:04
  • $\begingroup$ Hi Richard, I know that YT channel, as well as the caching mechanism. Right now I am trying to speed things up with Numba + Cuda for large arrays. Another idea would be to maybe port most of the code externally and let it run in a parallel instance + IO on a Ramdisk idk yet $\endgroup$
    – radoo
    May 6, 2021 at 18:24
1
$\begingroup$

Animation nodes have fromNumpyArray() function which can be used to convert numpy arrays without much overhead. For example a 1d array can be converted to float list by DoubleList.fromNumpyArray(myArray.astype('float64')).

Here you can see conversion speed for 1million numbers: enter image description here

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .