3 ms·
Local variables in CPython are stored in the stack frame and accessed via LOAD_FAST and STORE_FAST without doing anything with x as a string or a hash table: ht
by jashmatthews 6y ago
Local variables in CPython are stored in the stack frame and accessed via LOAD_FAST and STORE_FAST without doing anything with x as a string or a hash table: http://stupidpythonideas.blogspot.com/2015/12/how-lookup-works.html http://stupidpythonideas.blogspot.com/2015/12/how-lookup-wor...
- mjburgess 6y agoMy claim there was only that it was reified in memory, not that in the case of loading x, you had to use it. Though it is worth noting that you dont. In general the point stands, the reason for slowness is indirection & reification. (Not sure why i'm downvoted).
- jashmatthews 6y agoThe locals dict is lazily created from the locals in the stack frame. No dict there unless you use it. The article I linked to before has a really good explanation of this. len() only causes one dictionary lookup and then it's cached. > This is necessary, in general, to deliver on the dynamic lang. features python provides. It's the most obvious way to implement these features of dynamic languages but not at all necessary. https://www.infoworld.com/article/2074780/avoiding-hash-lookups-in-a-ruby-implementation.html https://www.infoworld.com/article/2074780/avoiding-hash-look... https://bibliography.selflanguage.org/_static/pics.pdf https://bibliography.selflanguage.org/_static/pics.pdf