Re: [Python-Dev] Idea: Dictionary references

2015年12月17日 15:34:54 -0800

2015年12月17日 23:17 GMT+01:00 Andrew Barnert via Python-Dev
<[email protected]>:
> Builtins do two dict lookups.
>
> So, the only thing you can optimize there is builtins. But maybe that's worth 
> it.
FYI I implemented an optimization in FAT Python to avoid lookups for
builtin functions, builtin functions are copied to code constants at
runtime:
https://faster-cpython.readthedocs.org/fat_python.html#copy-builtin-functions-to-constants
It's nothing new, it's the generalization of common hacks, like 'def
func(len=len): return len(3)'.
The optimization is restricted to loading builtin symbols which are
not expected to be modified ;-)
(Right now the optimization is disabled by default, because the
optimizer is unable to detect when builtins are modified in the
current function, and so it breaks the Python semantic.)
> Class attributes (including normal methods, @property, etc.) do two or more 
> dict lookups--first the instance, then the class, then each class on the 
> class's MRO.
Note: Types have an efficient cache for name lookups ;-) Thanks for
this cache, it's no more an issue to have a deep hierarchy of classes.
Victor
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to