Does a zip slow multithreading down?


#1

Because I needed to use an array in array for my function (I believe) I use the python zip function to make an array of arrays.
I find that the function that was written in python was amazingly slower than the regular grasshopper function. Am I doing something wrong or is the zip thing slowing everything down?

import ghpythonlib.components as ghcomp
import ghpythonlib.parallel

z = zip(x, y)

def rule_surf(i):
    return ghcomp.RuledSurface(i[0], i[1])

a = ghpythonlib.parallel.run(rule_surf, z, True)

Greeting Jesse


(Steve Baer) #2

Do you have a sample that I can test?


#3

python zip example.gh (9.3 KB)

Yes, here it is

please do not mind the imbicile peace if C# inbetween.

I’m trying to create a realtime surface out of my kinect output.


(Steve Baer) #4

The very first time a script is run there is a large overhead with respect to initializing the python runtime and “compiling” the script.If this is what you are looking at with respect to performance times then you are getting mislead by the numbers.

Here’s something to try. Add another input to your python component (call it z since that’s what the default will create and we won’t really use it.) Wire a toggle up to the z input and don’t change any of your code. Now click the toggle on and off and look at the performance times change.
python zip example.gh (8.7 KB)


#5

Ah okay.

well actually this did work, but only after I restarted Rhino.

Don’t know if I’m fond of the “if it doesn’t work, restart the system”, but, I do like that it works now, and it seems to work rather fast!

thank you.


#6

I retried this and made it so that I can change the the vector distance of the move. This way the list is different each time it runs.

Now it definitly slows down again. This is not chanched by restarting anything.

python zip example.gh (12.8 KB)


(Steve Baer) #7

You don’t need to restart Rhino. I meant that the very first time your grasshopper definition is evaluated with a python script in it, there is some overhead which will produce slower performance results than you expect.

Open the grasshopper definition that you sent and just start double clicking on the toggle a bunch of times. You’ll see that the performance dramatically improves for the python component after a couple toggles.

As a side note, I wouldn’t personally multithread this component since it already runs extremely fast in serial.


#8

Dear steve,

I was wondering if a multithreaded pythonscript would be faster opposed to a multithreaded C#?

Maybe this is a stupid question, but because I’m more familiar to java syntax, it would be more convenient.


(Steve Baer) #9

Multithreaded C# will be marginally faster, but it will be a lot more work. I am using the term marginally because you typically are multithreading calls into other functions in Rhino which take a long time. C# and python are typically a thin layer of glue code that call into larger library functions written in lower level rhino C++ code.