[Python-Dev] PEP 550 v3
yselivanov.ml at gmail.com
Mon Aug 21 17:44:53 EDT 2017
On Mon, Aug 21, 2017 at 5:39 PM, Koos Zevenhoven <k7hoven at gmail.com> wrote:
>> In the current version of the PEP, generators are initialized with an
>> empty LogicalContext. When they are being iterated (started or
>> resumed), their LogicalContext is pushed to the EC. When the
>> iteration is stopped (or paused), they pop their LC from the EC.
> Another quick one before I go: Do we really need to push and pop a LC on
> each next() call, even if it most likely will never be touched?
Yes, otherwise it will be hard to maintain the consistency of the stack.
There will be an optimization: if the LC is empty, we will push NULL
to the stack, thus avoiding the cost of allocating an object.
I measured the overhead -- generators will become 0.5-1% slower in
microbenchmarks, but only when they do pretty much nothing. If a
generator contains more Python code than a bare "yield" expression,
the overhead will be harder to detect.
More information about the Python-Dev