Speed up Python by up to 5% ?

Neil Schemenauer nas at python.ca
Thu Jul 25 12:18:38 EDT 2002


Edward K. Ream wrote:
> It may be possible to speed up the Python interpreter 3% to 5% with a
> trivial modification.

The "things to do" logic cannot be moved into the SET_LINENO opcode
because "python -O" removes the SET_LINENO instructions.  You should
work from the CVS source if you want to work on this optimization.  The
CVS version of the code already has some optimizations over 2.2.x.
Also, be aware that the code in ceval.c is touchy.  It's easy to get a
5% speedup on one type of CPU while losing 5% an another.  It's also
highly dependent on the benchmark used.

The current thinking is that a 10% to 15% speedup could be had by
changing ceval to use a register VM rather than a stack VM.  Skip
Montanaro has started work on a register VM.  I've ported his work from
Python 1.5.2 to 2.x.  The register VM is nearly done.  The major work
remaining is to modify the compiler.  The current compiler has gotten
really hairy over the years.  Jeremy Hylton is working on a new one for
Python 2.3.  Since it should be much easier to modify the new compiler
I'm going to wait until it's done rather than trying to modify the old
one.

  Neil




More information about the Python-list mailing list