Hello! I can shed some light on these.
I tried to work the Python Loop part with C++ MPxCommand, but I couldn’t find a way to return data by executing the Arguments in the form of Float3Array (Point Positions) and the corresponding command. (Return : IntArray)
If you are certain that looping isn’t going to be fast enough in Python, which I don't doubt, then yes this is what I would do. You won’t be able to return data outside of simple types like integers, floats and strings. But what you can do is serialise the data into e.g. JSON and output a string, and then deserialise it from Python. This is what I normally do. At a certain point, deserialising can become a bottleneck, at which point you have a JSON deserialiser in PySide2 which may be faster.
It is said that the part can be written in C++ using PyBind, but I know that the For Loop speed is limited due to the same GIL issue. Is there any way to solve it??
This point was what prompted me to reply - don’t do it! :D
Both MPxCommand and PyBind can work outside of any GIL - they are both called outside of Python - and while PyBind can return more complex types like vectors and even Python objects it is terribly inconvenient to work with in Maya. Because Maya - and Python in general - cannot reload or unload a binary Python module. Yes, you read that right. Once you import myBinaryModule
you cannot unload it. At all. The only recourse is restarting Maya.
Other than that, if that isn’t a problem, then PyBind is a good option for this. You can even pass a NumPy data structure, which would bypass Python even further and keep all data - especially heavy data - in C++ and be as fast as it can be.
It seems that there is no way to increase the speed of the current Python Loop by raising the speed of the loop as much as possible.
Hard to say without having an example. Loops in Python shouldn’t be a bottleneck in general; but it’s possible the repeated access to a Maya API class could. Are you able to share a small reproducible? Would be curious to see what the problem may be.
Best,
Marcus
--
You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email to python_inside_m...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/cc20157f-7440-454a-a230-e5cd1d84e47en%40googlegroups.com.
Thanks, the first potential optimisation I can spot is the use of Maya API 1.0. I would take 2.0 for a spin also - i.e. from maya.api import OpenMaya
- I would expect either a small or major improvement, since there is less serialisation going on between Python and C++ in 2.0.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/fb93a06b-4cdb-4c94-bf1b-f42d2b8918dan%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2467c3ef-bdf0-4fca-994e-4edd79977b18n%40googlegroups.com.