algorithmic modeling for Rhino

Demonstrating Recursion: Any idea why ghpythonlib runs so slowly?

Hi All,

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.

Views: 579


Reply to This

Replies to This Discussion

Hi Gwyll

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.


Giulio Piacentino
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.






  • Add Photos
  • View All

© 2018   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service