Author pitrou
Recipients pitrou
Date 2008-03-22.22:28:28
SpamBayes Score 0.0607198
Marked as misclassified No
Message-id <1206224909.42.0.227263347483.issue2459@psf.upfronthosting.co.za>
In-reply-to
Content
This is a preliminary patch to speedup for and while loops (it will also
be able to speedup list comps and gen comps, if I get to do it).
The patch works by putting the loop condition test at the end of loop,
which allows removing one JUMP_ABSOLUTE byte code out of the critical path.

For this two new opcodes are introduced:
- FOR_ITER2 is the same as FOR_ITER except that it does an /absolute/
jump if the iterator is /not/ exhausted (when other uses of FOR_ITER are
replaced with FOR_ITER2, we can of course restore the original naming)
- JUMP_ABS_IF_TRUE /pops/ the top of the stack and does an absolute jump
if its value is true

Some micro-benchmarks:

./python -m timeit "for x in xrange(10000): pass"
Before: 1000 loops, best of 3: 782 usec per loop
After: 1000 loops, best of 3: 412 usec per loop

./python -m timeit "x=100" "while x: x -= 1"
Before: 10000 loops, best of 3: 22.1 usec per loop
After: 100000 loops, best of 3: 16.6 usec per loop

./python Tools/pybench/pybench.py -t ForLoops
Before: 365ms per round
After: 234ms per round

Also, pystone gets 5% faster (from 43300 to 45800).

Now for the less shiny things:

1. I'm having problems modifying the pure Python compiler module. For
some reasons it seems to have stricter requirements than compile.c
itself does (!); I get some assertion error in
compiler.pyassem.FlowGraph.fixupOrderHonorNext as soon as a loop gets
non-trivial.

2. Line numbers probably need to be fixed. The lnotab format may even
have to be adapted in order to accomodate non-monotonically increasing
line numbers.

Is there some interest in this patch? If yes, I'd like to have your
input on the two bullet points above :)
History
Date User Action Args
2008-03-22 22:28:29pitrousetspambayes_score: 0.0607198 -> 0.0607198
recipients: + pitrou
2008-03-22 22:28:29pitrousetspambayes_score: 0.0607198 -> 0.0607198
messageid: <1206224909.42.0.227263347483.issue2459@psf.upfronthosting.co.za>
2008-03-22 22:28:28pitroulinkissue2459 messages
2008-03-22 22:28:28pitroucreate