[Twisted-Python] Re: GUI responsiveness

Jasper jasper at peak.org
Fri Sep 16 09:37:27 EDT 2005


Antoine Pitrou wrote:

>>class PyuiClient( NetworkClient ):
>>    def __init__( self  ):
>>        # ...
>>        self._pyuiRefresh( .001 )
>>
>>    def _pyuiRefresh( self, delay ):
>>        pyui.draw()
>>        pyui.update()
>>        reactor.callLater( delay, self._pyuiRefresh, delay )
>>    
>>
>
>This looks like a busy wait loop. It will eat a good chunk of the CPU
>time (depending on the time taken by each "_pyuiRefresh" iteration) and
>your laptop users (if there any) may not be very happy... It may slow
>down other apps tooo.
>  
>

It's not a busy wait loop, whenever it's not doing anything control is 
relinquished to twisted.  The .001 second delay /is/ really short, and I 
had originally expected something closer to the screen refresh rate like 
.01, but after testing I found that .001 performed better.  To be honest 
I don't fully understand why this is the case, as it seems like this 
would be wastefull, but it works fast enough I can't really justify the 
time it would take to profile it and figure out exactly what's going on.

Anyway, I get 60 FPS, idling CPU use is 5%, and I develop on an older 
laptop.  Since this is a game I don't much care if it slows down other 
apps, which it does a little.  I have no doubt that it could be more 
efficient, but considering I don't have any speed problems I'm perfectly 
happy trading this off for
code simplicity.

-Jasper




More information about the Twisted-Python mailing list