Tweak comments on performance impact based on current implementation

This commit is contained in:
Nick Coghlan 2009-03-15 12:41:42 +00:00
parent db055e0d40
commit cd484999f2
1 changed files with 19 additions and 4 deletions

View File

@ -166,7 +166,7 @@ then handles and suppresses::
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 @@ the same semantic differences as are seen with the ``combined()`` context
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 @@ References
.. [3] Import-style syntax to reduce indentation of nested with statements
(http://mail.python.org/pipermail/python-ideas/2009-March/003188.html)
Copyright
=========