[Python-ideas] New PEP 550: Execution Context

Yury Selivanov yselivanov.ml at gmail.com
Fri Aug 11 20:12:34 EDT 2017


[duplicating my reply cc-ing python-ideas]

> Is a new EC type really needed? Cannot this be done with collections.ChainMap?

No, not really. ChainMap will have O(N) lookup performance where N
is the number of contexts you have in the chain. This will degrade
performance of lookups, which isn't acceptable for some potential
EC users like decimal/numpy/etc.

Inventing heuristics to manage the chain size is harder than making
an immutable dict (which is easy to reason about.)

Chaining contexts will also force then to reference each other, creating
cycles that GC won't be able to break.

Besides just performance considerations, with ChainMap design
of contexts it's not possible to properly isolate state changes
inside of generators or coroutines/tasks as it's done in the PEP.

All in all, I don't think that chaining can solve the problem. It will likely
lead to a more complicated solution in the end (this was my initial
approach FWIW).

Yury


More information about the Python-ideas mailing list