::more pymel speed findings::
July 19th, 2010 by hamish download the zooToolBoxI started poking the speed problems that plague pymel a bit more. It seems the problem may lie in the simple fact that instantiating MObject’s is expensive… try it out:
from maya.OpenMaya import * import time import maya.cmds as cmd def asMObject( item ): sel = MSelectionList() sel.add( item ) tmp = MObject() sel.getDependNode( 0, tmp ) return tmp def test(): start = time.clock() for obj in cmd.ls(): asMObject( obj ) print 'time taken %0.3f' % (time.clock()-start)
This is pretty simple stuff. Simply iterating over all nodes in a blank scene and casting them to MObjects individually is slow. It takes 0.05 seconds on my machine on an empty scene. Doing the same thing with pymel takes about 0.21 seconds which is a little more than 4 times slower than this. Quite a leap from 350x.
So it seems Autodesk is largely to blame for some bloated script bindings.
From this little bit of investigation I’m not really convinced that its possible to have a fast unified abstraction of mel/api without help from Autodesk in cleaning up and speeding up their wrappers.
What might be interesting is looking into subclassing unicode and lazily populating the instance with api data as its requested from script to minimize the time spent instantiating maya’s object types. Incidentally pymel’s PyNode class used to inherit from unicode, but I’m unaware of how aggressive it was with lazy evaluation. I believe the reason Chad moved away from this idea in pymel was because strings in python are immutable and node names in maya are not. Having an immutable object represent mutable data is kinda sucky. But hey, we have to deal with this currently anyway, so its not like we’re moving backwards. Just not as far forward as we’d like.
The sucky thing about doing the lazy evaluation thing is that it’d be tricker to leverage inheritance – you wouldn’t want to determine the most appropriate class to cast the node as on instantiation because thats where it becomes expensive. So instead you’d have to dynamically populate the instance dictionary as functionality was requested.
Anyway… Once again we’re at the mercy of some shitty corner cutting from Autodesk.
In other news – has anyone seen how WELL blender has integrated scripting? Way better than any dcc app I’ve ever seen.




