[Python-ideas] More compact bytecode

Serhiy Storchaka storchaka at gmail.com
Thu Feb 4 11:55:43 EST 2016


On 04.02.16 18:16, Victor Stinner wrote:
>> 1. Add 1-byte dedicated opcodes for most used opcodes with arguments.
>
> It means duplicating a lot of code in ceval.c, no? (Even if we use C
> #define "templates"). I dislike this option.

This needs to add less than 40 lines of code in ceval.c. 5-line macro 
and 1 line per new opcode. A little more lines need to be added to 
compiler, peephole optimizer, opcode.py, opcode.h and the documentation.

>> 2. Use 16-bit opcodes as in WPython.
>
> IMHO this is a much more interesting option.
>
> It would be great to remove "if (HAS_ARG(opcode)) oparg = NEXTARG();"
> and always get the argument from the 16-bit opcode. This if() adds
> more work to the CPU which has to flush the pipeline on branch
> misprediction. Usually, it doesn't matter. For this if() is really
> part of the hot path code Python, it's the most important loop running
> the bytecode. So any instruction matters here ;-)

Actually in common case this "if" is executed at compile time. But I 
expect a benefit from using simple read of 16-bit value instead of 3 
reads of 8-bit values.




More information about the Python-ideas mailing list