3 ms·
Yes there is lookup, always lookup. Dynamic language, something in loop could change what lstr is. Each "dot" incurs lookup. Your example reminds me of one i
by njharman 14y ago
Yes there is lookup, always lookup. Dynamic language, something in loop could change what lstr is.
Each "dot" incurs lookup. Your example reminds me of one idiom. Assigning nested.look.up to local var for access inside loop.
- dmorgan 14y ago>Yes there is lookup, always lookup. Dynamic language, something in loop could change what lstr is. And why is that presented as something inevitable? The interpreter/compiler could analyze that part and see that the function/name is not changed during the loop, and cache for that. I'd guess that PyPy tries to do it that way, anyway...
- lvh 14y agoYes, that's one of the many optimizations PyPy does, however it's only a very limited one. PyPy goes much, much deeper than this, with tools like function inlining and escape analysis.