Hacker News new | ask | show | jobs
by MichaelMoser123 4088 days ago
regarding the speed issue: i looked at python 2.7 - here the interpreter is creating a dictionary for each function frame, now local variables are looked up by name of variable in this dictionary ! (globals have their separate namespace dictionary)

(i made a tracing tool that traces a python program and prints out all accessed variables - it actually makes use of this by-name-lookup-feature http://mosermichael.github.io/cstuff/all/projects/2015/02/24... )

i think that's quite wasteful, fixing variable access so that it is by some internal index and not by name would probably be a big improvement, even without changing the global interpreter lock.

2 comments

Closures might make this difficult, since a variable might be referenced by name before it's defined in any scope.
Variable access already works by index, not by name. Normally, LOAD_FAST and STORE_FAST are used.