[Python-checkins] r70382 - peps/trunk/pep-0377.txt
nick.coghlan
python-checkins at python.org
Sun Mar 15 13:41:43 CET 2009
Author: nick.coghlan
Date: Sun Mar 15 13:41:42 2009
New Revision: 70382
Log:
Tweak comments on performance impact based on current implementation
Modified:
peps/trunk/pep-0377.txt
Modified: peps/trunk/pep-0377.txt
==============================================================================
--- peps/trunk/pep-0377.txt (original)
+++ peps/trunk/pep-0377.txt Sun Mar 15 13:41:42 2009
@@ -166,7 +166,7 @@
With the proposed semantic change in place, the contextlib based examples
above would then "just work", but the class based version would need
-adjustment to take advantage of the new semantics::
+a small adjustment to take advantage of the new semantics::
class CM(object):
def __init__(self):
@@ -220,17 +220,31 @@
manager in the above example.
+Performance Impact
+==================
+
+Implementing the new semantics makes it necessary to store the references
+to the ``__enter__`` and ``__exit__`` methods in temporary variables instead
+of on the stack. This results in a slight regression in ``with`` statement
+speed relative to Python 2.6/3.1. However, implementing a custom
+``SETUP_WITH`` opcode would negate any differences between the two
+approaches (as well as dramatically improving speed by eliminating more
+than a dozen unnecessary trips around the eval loop).
+
+
Reference Implementation
========================
-In work.
+Patch attached to Issue 5251 [1]. That patch uses only existing opcodes
+(i.e. no ``SETUP_WITH``).
Acknowledgements
================
-James William Pye both raised the issue and suggested the solution
-described in this PEP.
+James William Pye both raised the issue and suggested the basic outline of
+the solution described in this PEP.
+
References
==========
@@ -244,6 +258,7 @@
.. [3] Import-style syntax to reduce indentation of nested with statements
(http://mail.python.org/pipermail/python-ideas/2009-March/003188.html)
+
Copyright
=========
More information about the Python-checkins
mailing list