[Python-Dev] Bytecode analysis
Christian Tismer
tismer@tismer.com
Wed, 26 Feb 2003 00:19:18 +0100
Damien Morton wrote:
> Ive done a static analysis of the bytecodes from compiling the python
> standard library:
>
> Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
>
>
> Some stats about JUMP_IF_FALSE opcodes
>
> Of the 2768 JUMP_IF_FALSE opcodes encountered, 2429 have a POP_TOP on
> both branches.
>
> Id like to propose that JUMP_IF_FALSE consume the top-of-stack.
I'm all against changing existing opcodes for a minor
speed-up. Real speed-up is available by a specializing
compiler which turns things into real code.
If you really want to change the engine, I would consider
to emit an extra opcode and try how the change performs
against a couple of applications. I doubt the effect, since
the little POP_TOP is pretty fast.
Where you really can save some time is to shortcut some
of the very short opcodes to not jump back to the ticker
counting code, but into a shorter circle. This avoids
quite some register moves and gives some local optimization
possibilities.
I would anyway suggest not to change the semantics of
existing opcodes for just little win.
...
> Id like to propose the following opcodes be added
> LOAD_CONST(NONE)
> LOAD_CONST(1)
> LOAD_CONST(0)
> LOAD_CONST(EMPTY_STR)
I'd be careful here, too. The interpreter loop is quite
large, already, and there is a good chance to loose
locality of reference by adding a little bit of code.
I had that several times. You don't think you changed
much, but where are these 10 percent gone now?
Not trying to demoralize you completely, but there are
limits about what can be gathered by optimizing the
interpreter loop. There was once the p2c project, which
gave an overall improvement of 25-40 percent, by totally
removing the interpreter loop.
Since I knew that, I stopped wasting brain cycles on
optimizing it, because the possible win is not really
promising. There are much better ways to speed Python up.
One is to completely rewrite Python in Python and applying
a specializing compiler to everything. This is what we
are trying on pypy-dev.
cheers - chris
--
Christian Tismer :^) <mailto:tismer@tismer.com>
Mission Impossible 5oftware : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9a : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 89 09 53 34 home +49 30 802 86 56 pager +49 173 24 18 776
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/