[Python-Dev] Idea: Dictionary references

Victor Stinner victor.stinner at gmail.com
Fri Dec 18 01:49:46 EST 2015


Le vendredi 18 décembre 2015, Andrew Barnert via Python-Dev <
python-dev at python.org> a écrit :
>
> >> Builtins do two dict lookups.
> >
> > Two?
>
> Actually, I guess three: first you fail to find the name in globals, then
> you find __builtins__ in globals, then you find the name in __builtins__ or
> __builtins__.__dict__.
>

Getting builtins from globals in done when the frame object is created, and
the lookup is skipped in the common case if qu recall correctly. LOAD_NAME
does a lookup on function globals, if the key doesn't exist (common case
for builtins), a ceond lookup is done in frame builtins. Open
Python/ceval.c and see to code. There is an optimisation for fast lookup in
two dict.

Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20151218/78db6505/attachment.html>


More information about the Python-Dev mailing list