[Python-Dev] Bytecode idea

Christian Tismer tismer@tismer.com
Wed, 26 Feb 2003 05:32:58 +0100


Raymond Hettinger wrote:
>> Maybe it also makes sense to use indexing into a static
>> array, instead of the case construct. 
> 
> That makes sense to me.  I would be stunned if adding
> an inner case statement helped (the cost of a second
> unpredicable branch would have to be less than the 
> cost of cache line utilization of a bit of redundant code).

It depends. The unpredictable branche isn't better than
the unpredictable call to a function from an indexed table.
The case just might have the advantage to live in the
same code segment, at least as I know from the M$ compiler.
The indirect jump table may live elsewhere in the data...

> My thought on the big case statement was to have it do
> more disaggregration.  For instance, each op code already
> knows whether it needs an oparg, so there is no need for
> a separate test for it on every pass with HAS_ARG(opcode).

This is true. I used this in my optimization from two
years ago, and moved the oparg preparation into the
opcode cases, not doing any test, but just fetching
the argument. I also turned this into macros which
added to the insn pointer only once.
Incredible but true: Most of the win I gathered was
by typecasting the oparg access differently into
a reference to a short int, instead of oring two
bytes. But this is due to the dumbness of those compilers...

>>While I don't know if this really makes the interpreter
>>more efficient
> 
> Time it and see.

No, I will not. I just wanted to give some hints to where
I see optimizations which might be promising. But I have
no time to try this by myself. Also, as already stated,
I don't see enough to be gatherable at all, to start an
effort.
What can I win: 25 to 40 percent? What I'm after is
an order of magnitude.

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/