variable declaration

Nick Coghlan ncoghlan at iinet.net.au
Wed Feb 9 07:22:21 EST 2005


Antoon Pardon wrote:
> Op 2005-02-08, Nick Coghlan schreef <ncoghlan at iinet.net.au>:
>>The CPython *_FAST opcodes relate to functions' local variables. Behind the 
>>scenes they are implemented as integer indexing operations into a pre-sized C 
>>array. Operations don't come much faster than that :)
> 
> 
> I don't follow. AFAIR my remark here above was about the STORE opcode.
> But you seem to react to it as if I am talking about STORE_FAST.

I've been talking about rebinding function local variables all along - which 
means STORE_FAST. I may not have made that explicit, though.

However, even in the general case, "check it already exists and overwrite it if 
it does" is going to be slower than "just store it".

The reason is that, if checking for the existence of the name first somehow 
provides a speed advantage (I still can't see how it could), then the latter 
case of unconditional storage can check for the names existence *just to get the 
speed advantage* (the difference being that the name gets bound irrespective of 
whether it originally existed or not).

Anything that could be used to speed up a rebinding, could most likely be used 
to speed up a standard binding at the same point in the code. So, while it might 
be possible to get rebinding code which isn't any slower than a standard 
binding, it seems practically impossible to do anything to get rebinding code to 
be *faster*.

Cheers,
Nick.

P.S. FWIW, there is no such thing as a STORE opcode, there are only STORE_* opcodes:

Py> print "\n".join([oc for oc in opcode.opname if "STORE" in oc])
STORE_SLICE+0
STORE_SLICE+1
STORE_SLICE+2
STORE_SLICE+3
STORE_SUBSCR
STORE_NAME
STORE_ATTR
STORE_GLOBAL
STORE_FAST
STORE_DEREF

-- 
Nick Coghlan   |   ncoghlan at email.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://boredomandlaziness.skystorm.net



More information about the Python-list mailing list