Python and the need for speed

bartc bc at freeuk.com
Tue Apr 18 19:18:42 EDT 2017


On 19/04/2017 00:08, Gregory Ewing wrote:
> Erik wrote:
>> When considering special-casing this opcode sequence, remember that
>> in-place operations can be performed on anonymous objects (i.e., those
>> referenced by a collection and not bound directly to a namespace):
>
> I think this means you would want multiple versions of the +=1 opcode:
> ADD_ONE_TO_NAME, ADD_ONE_TO_ITEM, ADD_ONE_TO_ATTR, etc. Essentially
> one for each variant of the STORE operation.

This where it starts to get out of hand, if using a fixed set of byte-codes.

I suggested earlier in the thread using special references, which can be 
created for each kind of access (GLOBAL, FAST, INDEX etc). But then you 
have one REF type and only need ADD_ONE_TO_REF.

> Or you might choose to optimise just the local name case, on the
> basis that the overhead of things like item and attribute lookup
> would probably swamp any possible gains.

But you would reduce two lookups to one, so the gains might be greater 
with those more elaborate accesses.

-- 
bartc



More information about the Python-list mailing list