Showing content from http://mail.python.org/pipermail/python-dev/attachments/20121209/7b689eef/attachment.html below:
<p dir="ltr">Sounds good to me. No PEP needed, just a tracker item, tests, review etc...</p>
<p dir="ltr">--Guido van Rossum (sent from Android phone)</p>
<div class="gmail_quote">On Dec 9, 2012 2:24 PM, "Mark Shannon" <<a href="mailto:mark@hotpy.org">mark@hotpy.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi all,<br>
<br>
The current CPython bytecode interpreter is rather more complex than it needs to be. A number of bytecodes could be eliminated and a few more simplified by moving the work involved in handling compound statements (loops, try-blocks, etc) from the interpreter to the compiler.<br>
<br>
This simplest example of this is the while loop...<br>
while cond:<br>
body<br>
<br>
This currently compiled as<br>
<br>
start:<br>
if not cond goto end<br>
body<br>
goto start<br>
end:<br>
<br>
but it could be compiled as<br>
<br>
goto test:<br>
start:<br>
body<br>
if cond goto start<br>
<br>
which eliminates one instruction per iteration.<br>
<br>
A more complex example is a return in a try-finally block.<br>
<br>
try:<br>
part1<br>
if cond:<br>
return X<br>
part2<br>
finally:<br>
part3<br>
<br>
Currently, handling the return is complex and involves "pseudo exceptions", but if part3 were duplicated by the compiler, then the RETURN bytecode could just perform a simple return.<br>
The code above would be compiled thus...<br>
<br>
PUSH_BLOCK try<br>
part1<br>
if not X goto endif<br>
push X<br>
POP_BLOCK<br>
part3 <<< duplicated<br>
RETURN_VALUE<br>
endif:<br>
part2<br>
POP_BLOCK<br>
part3 <<< duplicated<br>
<br>
The changes I am proposing are:<br>
<br>
Allow negative line deltas in the lnotab array (bytecode deltas would remain non-negative)<br>
Remove the SETUP_LOOP, BREAK and CONTINUE bytecodes<br>
Simplify the RETURN bytecode<br>
Eliminate "pseudo exceptions" from the interpreter<br>
Simplify (or perhaps eliminate) SETUP_TRY, END_FINALLY, END_WITH.<br>
Reverse the sense of the FOR_ITER bytecode (ie. jump on not-exhausted)<br>
<br>
<br>
The net effect of these changes would be:<br>
Reduced code size and reduced code complexity.<br>
A small (1-5%)? increase in speed, due the simplification of the<br>
bytecodes and a very small change in the number of bytecodes executed.<br>
A small change in the static size of the bytecodes (-2% to +2%)?<br>
<br>
Although this is a quite intrusive change, I think it is worthwhile as it simplifies ceval.c considerably.<br>
The interpreter has become rather convoluted and any simplification has to be a good thing.<br>
<br>
I've already implemented negative line deltas and the transformed while loop: <a href="https://bitbucket.org/markshannon/cpython-lnotab-signed" target="_blank">https://bitbucket.org/<u></u>markshannon/cpython-lnotab-<u></u>signed</a><br>
I'm currently working on the block unwinding.<br>
<br>
So,<br>
Good idea? Bad idea?<br>
Should I write a PEP or is the bug tracker sufficient?<br>
<br>
Cheers,<br>
Mark.<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org" target="_blank">Python-Dev@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-dev" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="http://mail.python.org/mailman/options/python-dev/guido%40python.org" target="_blank">http://mail.python.org/<u></u>mailman/options/python-dev/<u></u>guido%40python.org</a><br>
</blockquote></div>
RetroSearch is an open source project built by @garambo
| Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4