[Python-ideas] More compact bytecode

Victor Stinner victor.stinner at gmail.com
Thu Feb 4 11:16:07 EST 2016


2016-02-04 14:03 GMT+01:00 Serhiy Storchaka <storchaka at gmail.com>:
> Damien George mentioned [1] that in MicroPython there are 16 dedicated
> opcodes for loading from positions 0-15, and 16 for storing to these
> positions. This not only makes a bytecode more compact, but might make
> CPython slightly faster too.

MicroPython has a very important requirements on disk and memory
footprint. I don't think that it's the case for CPython.


> 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.


> 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 ;-)

You just have to handle correctly EXTENDED_ARG to large arguments.

Victor


More information about the Python-ideas mailing list