[Python-ideas] New PEP 550: Execution Context

Nathaniel Smith njs at pobox.com
Sat Aug 12 01:33:14 EDT 2017


On Fri, Aug 11, 2017 at 10:17 PM, Guido van Rossum <guido at python.org> wrote:
> I may have missed this (I've just skimmed the doc), but what's the rationale
> for making the EC an *immutable* mapping? It's impressive that you managed
> to create a faster immutable dict, but why does the use case need one?

In this proposal, you have lots and lots of semantically distinct ECs.
Potentially every stack frame has its own (at least in async code). So
instead of copying the EC every time they create a new one, they want
to copy it when it's written to. This is a win if writes are
relatively rare compared to the creation of ECs.

You could probably optimize it a bit more by checking the refcnt
before writing, and skipping the copy if it's exactly 1. But even
simpler is to just always copy and throw away the old version.

-n

-- 
Nathaniel J. Smith -- https://vorpus.org


More information about the Python-ideas mailing list