4 ms·
Unusual is a strange qualifier here. Removing a dereference leading to a speedup is probably one of the few almost universal optimizations.
by mirashii 8y ago
Unusual is a strange qualifier here. Removing a dereference leading to a speedup is probably one of the few almost universal optimizations.
- gameswithgo 8y agoPeople do it in C# a lot with Count and Length on Lists and Arrays and it ruins array bounds check elision. It is something that compilers do for you, in this context, in most programming environments.
- uryga 8y agoUnfortunately, Python being hopelessly dynamic, `A.b` could involve executing arbitrary code and side effects depending on what `A` is. So hoisting `A_b = A.b` out of the loop may produce different results and thus can't be done automatically without some kind-of incredibly (impossibly?) smart static analysis :( (though perhaps a JIT could perform this optimization for the usual, non-surprising path)
- snovv_crash 8y agoIt isn't the removed dereference that speeds it up though, it is placing the pointer into the local scope, which is searched before the global scope.