Message64342
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 -s "x=10000" "while x: x -= 1"
Before: 1000000 loops, best of 3: 0.237 usec per loop
After: 10000000 loops, best of 3: 0.176 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 :) |
|
Date |
User |
Action |
Args |
2008-03-25 18:21:12 | fdrake | unlink | issue2459 messages |
2008-03-22 22:25:05 | pitrou | set | spambayes_score: 0.0607198 -> 0.060719807 recipients:
+ pitrou |
2008-03-22 22:25:05 | pitrou | set | spambayes_score: 0.0607198 -> 0.0607198 messageid: <1206224705.13.0.0890165071291.issue2459@psf.upfronthosting.co.za> |
2008-03-22 22:25:03 | pitrou | link | issue2459 messages |
2008-03-22 22:25:02 | pitrou | create | |
|