[Python-Dev] Possible optimization for LOAD_FAST ? (original) (raw)

Benjamin Peterson benjamin at python.org
Tue Dec 28 18:24:36 CET 2010


2010/12/28 Lukas Lueg <lukas.lueg at googlemail.com>:

Consider the following code:

def foobar(x):  for i in range(5):  x[i] = i The bytecode in python 2.7 is the following:  2           0 SETUPLOOP              30 (to 33)  3 LOADGLOBAL              0 (range)  6 LOADCONST               1 (5)  9 CALLFUNCTION            1 12 GETITER  >>   13 FORITER                16 (to 32) 16 STOREFAST               1 (i)  3          19 LOADFAST                1 (i) 22 LOADFAST                0 (x) 25 LOADFAST                1 (i) 28 STORESUBSCR 29 JUMPABSOLUTE           13  >>   32 POPBLOCK  >>   33 LOADCONST               0 (None) 36 RETURNVALUE Can't we optimize the LOADFAST in lines 19 and 25 to a single load and put the reference twice on the stack?

Yes. Would it be useful? Unlikely.

-- Regards, Benjamin



More information about the Python-Dev mailing list