algorithmic modeling for Rhino
I thought I had come up with a clever way of introducing students to concepts of iteration and recursion by attempting to use the ghpython lib to re-write grasshopper networks as simple functions. Unfortunately there seems to be such a drastic performance hit from using the new ghpythonlib that the intended outcome of the exercise (demonstrating some self-organisation by iterating over a closest-point function hundreds of times) is ironically not really possible. Is there a way to improve performance that I've missed or is this unavoidable? Using rhinocommon objects is considerably faster.
I've attached the definition with the python script for speed comparisons. The intention was to design a simple algorithm, demonstrate iteration/recursion through copy-paste of clusters and then translate the algorithm to python.
Any suggestions appreciated, cheers.
I haven't written the ghcomplib library so I do not know every tiny detail, but I know that in order to instantiate functions in this version of Grasshopper, it has to do a series of additional minor steps, each of which will take a little extra time. This means that this library takes on average I would say 1-10% longer than Grasshopper components, which again I would say take 1-10% longer than RhinoCommon-only C# calls. As you can see, this is not really a big deal. On the other hand, we see here 1000% execution deterioration. So there's something else going on.
And the reason is the way "ghcomp.ClosestPoint" is approached.
If you give it a list of points it needs to search for, if can resuse speed-up structures that are created for the points among which it searches. Otherwise, this structure has to be recreated each time.
I did not spend too long after noticing that -- now the speed is about the same as in Grasshopper.
for Robert McNeel & Associates
Hi Giulio, thanks for the reply.
That makes a lot of sense - it is a relief to hear that it isn't an inherent issue with the library.
Good news! The library is now rewritten in Rhino WIP. http://discourse.mcneel.com/t/new-version-of-ghpythonlib-components...