Speed up Python by up to 5% ?

Pete Shinners pete at shinners.org
Thu Jul 25 12:30:15 EDT 2002


Edward K. Ream wrote:
>  18686 LOAD_FAST
>  14276 SET_LINENO
>   9635 LOAD_CONST
>   9555 POP_TOP
>   6721 LOAD_GLOBAL **
>   5890 CALL_FUNCTION **
>    ...
> total 96454
> 
> ** denotes "heavy hitter"
> 
> Dynamic execution frequencies will not match these static frequencies
> exactly, but I see no reason to suppose they will be wildly different.  If
> anyone has real dynamic data, I would like to see it :-)

i was always under the impression that some sort of "layered" switch 
statement could speed up execution. basically put the most frequent opcodes 
inside the toplevel switch. then a section of regular opcodes, and finally 
falling down to a switch statement with the rare opcodes.


switch(opcode):
{
     COMMON:
     default:
         switch(opcode)
         {
             REGULAR:
             default:
                 switch(opcode)
                 {
                     RARE:
                 }
         }
}

of course, some fine tuning might be required to get the most out of this, 
but it seems like an easy enough change? (maybe one day i'll bunker in and 
go for it). i'm guessing that further sampling of "dynamic execution 
frequencies" would tell what opcodes are most likely to go in which switch 
statement.

on the other hand, it's probably a pretty sensitive thing inside the 
bytecode processor. little changes can likely have unconsidered consequences.





More information about the Python-list mailing list