This is great for helping us find the functions that “should” be faster using multiple threads.
Here’s what I’ve figured out so far:
1 - MeshPlane intersection
There is a function in RhinoCommon called
which takes a list of planes as input. This is what the grasshopper component is directly calling. I can see why the code would be slower calling the function 1000 times on different threads passing in a single plane versus 1 time passing in 1000 planes. There is significant “setup” code for a data structure to generate the intersections inside of this function. The data structure is recreated in each threaded call which is what is slowing things down. We need to look at this function again and figure out a way to reuse the data structure in the multi-threaded case.
2 - Curve ClosestPoint Test
This one is a little strange and I still don’t know exactly why the code runs approximately the same speed as the single threaded solution. There must be something happening in the component code which is causing the overhead. I modified your script so I could test just using pure RhinoCommon calls in the parallel code instead of the component call (oh yeah, you can do that by the way ) and got a 2X speed boost.
import ghpythonlib.components as ghcomp
# True == use component function in parallel code
# False == just use RhinoCommon in the parallel code
useghcomp = False
#custom function that is executed by parallel.run
result = ghcomp.CurveClosestPoint(pt, curve).point
result = 
for point in pt:
rc, t = curve.ClosestPoint(point)
pt = ghpythonlib.parallel.run(curveCP, crv, True)
results = 
for curve in crv:
pt = results
I’m going to need to spend a little more time trying to figure out what the issue is here.
3 - MeshRay Test
This test does seem to run 3X faster on my computer than the serial version. One thing to point out is that you need to ignore the timing the very first time your python script is executed (or the first time after you edited the script.) There is significant overhead in “compiling” the script that doesn’t really help with figuring out timing issue. After you’ve editing a script click the “parallel” toggle a couple times to get a better feel for timing.
Thanks for sending in this sample, these are very useful for me to figure out the problem spots.