PEP 266: Optimizing Global Variable/Attribute Access
Skip Montanaro
skip at pobox.com
Wed Aug 15 09:54:41 EDT 2001
Peter> Hello Python Optimizers :-)
Peter> After reading PEP 266, I coded the following:
[ ... snip tests ... ]
Peter> So it seems that *without* the execution of the proposed
Peter> TRACK_OBJECT and UNTRACK_OBJECT there would be about a 31%
Peter> improvement. Unless I'm missing something fundamental, if the
Peter> compiler can be made smart enough to know where to put
Peter> TRACK_OBJECT and UNTRACK_OBJECT then why can't it do the code
Peter> transformation as above?
That's the plan. ;-)
Actually, if I do it right, PEPTest2 would work more like
def PEPTest2():
m = math.sin
c = 100000
while c:
l = []
f = l.append
for i in range(10):
f(m(i))
c -= 1
That is, math.sin would get cached at the earliest point where it is in
scope, which would be before the while loop.
--
Skip Montanaro (skip at pobox.com)
http://www.mojam.com/
http://www.musi-cal.com/
More information about the Python-list
mailing list