Magic Optimisation

simonwittber at gmail.com simonwittber at gmail.com
Sun Sep 4 23:49:06 EDT 2005


Hello People.

I've have a very tight inner loop (in a game app, so every millisecond
counts) which I have optimised below:

    def loop(self):
        self_pool = self.pool
        self_call_exit_funcs = self.call_exit_funcs
        self_pool_popleft = self.pool.popleft
        self_pool_append = self.pool.append
        check = self.pool.__len__
        while check() > 0:
            task = self_pool_popleft()
            try:
                task.next()
            except StopIteration:
                self_call_exit_funcs(task)
                return
            self_pool_append(task)

This style of optimisation has shaved _seconds_ from my iteration
cycle, esp. when I have many registered tasks, so this style of
optimisation is very important to me.

However, it is very ugly. Does anyone have any tips on how I could get
this optimisation to occor magically, via a decorator perhaps?

Sw.




More information about the Python-list mailing list