[Python-Dev] Speeding up instance attribute access
Fri, 08 Feb 2002 16:10:25 -0500
Guido van Rossum wrote:
> - The required global analysis is a bit hairy, and not something we
> already do. I believe that Jeremy thinks PyChecker already does
> this; I'm not sure if that means we can borrow code or just ideas.
The algorithm pychecker uses is pretty simple.
I think something like this should work:
for each method:
self = method.co_varnames
for each byte code in method:
if op == STORE_FAST and oparg == self:
break # we don't know self anymore
if (op == STORE_ATTR or op == LOAD_ATTR) and selfOnTop:
# we have an attribute store it off
selfOnTop = (LOAD_FAST and oparg == self)
Note that storing the attributes could be done during the compilation step.
This means that it should be simple housekeeping in the compiler to store
the info and not require another pass (as in pychecker).