Hacker News new | past | comments | ask | show | jobs | submit login

You can find out by using dis and checking what is load_fast, load_const or load_global. Attribute lookups are always just that as far as I know. The dot operator has a bunch of paths.



Yes thanks, I think that is right... LOAD_FAST and LOAD_CONST are by number, and used for local variables and constants.

LOAD_NAME, LOAD_ATTR, and LOAD_GLOBAL are all lookups by name, and are used for everything else: globals, object attributes and methods, modules, etc.

It seems that if Python had a static module system, all the lookups by name could be compiled down into lookups by number.

https://docs.python.org/3/library/dis.html#python-bytecode-i...


I'm not clear on the status of PEP 509, but it could/should make LOAD_NAME and LOAD_GLOBAL approach the speed of LOAD_FAST. It'll set a flag on the globals dict (or any dict?) that trips when the dict is mutated. Non-mutated dicts can have fast repeated lookups.

https://www.python.org/dev/peps/pep-0509/

Dictionaries got some sweet upgrades for v3.6.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: