On 18 March 2014 19:46, Maciej Fijalkowski <fijall at gmail.com> wrote: >> A question: how far away will this optimization apply? >> >> if x in d: >> do_this() >> do_that() >> do_something_else() >> spam = d[x] > > it depends what those functions do. JIT will inline them and if > they're small, it should work (although a modification of a different > dict is illegal, since aliasing is not proven), but at some point > it'll give up (Note that it'll also give up with a call to C releasing > GIL since some other thread can modify it). Surely in the presence of threads the optimisation is invalid anyway as other threads can run in between each opcode (I don't know how you'd phrase that in a way that wasn't language dependent other than "everywhere" :-)) so if x in d: # HERE spam = d[x] d can be modified at HERE. (If d is a local variable, obviously the chance that another thread has access to d is a lot lower, but do you really do that level of alias tracking?) Paul
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4