[IronPython] Optimized methods and serious performance issues

Jonathan Jacobs korpse-ironpython at kaydash.za.net
Thu May 25 09:46:09 PDT 2006


J. Merrill wrote:
> I know almost nothing about DirectX, am definitely not a Python guru, and
> have not experimented with IP in this area.  However, my impression is that
> there is a common Python "idiom" for speeding up method calls, which is to
> use a variable (often a local) to hold a reference to a "bound method" and
> make calls through that variable.  This avoids all the work that normally
> has to be done to figure out what actual method (the one associated with
> the instance, the class, the parent class, the parent class's parent, etc
> etc) is supposed to be called by a particular "callable" expression.
> 
> Whether this is appropriate in your case, I can't say.  For example, if the
> value of self.mesh can change while your loop is running, it won't give the
> right results to do methref = self.mesh.DrawSubset and then call methref(0)
>  in your loop, because this will call via whatever value mesh had been when
> you set methref.
> 
> If it's appropriate, have you tried that technique?

I'd forgotten about this, so I gave it a shot:

fun = self.mesh.DrawSubset
fun(0)

yielded no noticeable speedup, however:

fun = Direct3D.Mesh.DrawSubset
fun(self.mesh, 0)

yielded a significant speedup, oddly.
-- 
Jonathan

When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
                 -- Rinzai, ninth century Zen master


More information about the users mailing list