[Python-Dev] Adding a builtins parameter to eval(), exec() and __import__().

Victor Stinner victor.stinner at gmail.com
Fri Mar 9 13:50:14 CET 2012


> The reason I am proposing this here rather than on python-ideas is that
> treating the triple of [locals, globals, builtins] as a single
> "execution context" can be implemented in a really nice way.
>
> Internally, the execution context of [locals, globals, builtins]
> can be treated a single immutable object (custom object or tuple)
> Treating it as immutable means that it can be copied merely by taking a
> reference. A nice trick in the implementation is to make a NULL locals
> mean "fast" locals for function contexts. Frames, could then acquire their
> globals and builtins by a single reference copy from the function object,
> rather than searching globals for a '__builtins__'
> to find the builtins.

Creating a new frame lookup for __builtins__ in globals only if
globals of the new frame is different from the globals of the previous
frame. You would like to optimize this case? If globals is unchanged,
Python just increments the reference counter.

When globals is different from the previous frame? When you call a
function from a different module maybe?

Do you have an idea of the speedup of your optimization?

Victor


More information about the Python-Dev mailing list