Panda use a lot of CPU even if nothing is displayed

Hello, I’d like to decrease the CPU usage of my application and, while trying some stuff, I saw that Panda was taking a lot of CPU, even when nothing is done.

def main():
    import direct.directbase.DirectStart
    from pandac.PandaModules import ClockObject, PStatClient
    PStatClient.connect()
    FPS = 60
    globalClock = ClockObject.getGlobalClock()
    globalClock.setMode(ClockObject.MLimited)
    globalClock.setFrameRate(FPS)
    base.win.setActive(False)
    run()

if __name__ == '__main__':
    main()

With this code sample, nothing is displayed, the fps is set to 60, and it’s using mor than 60% of my CPU. If I decrease the FPS, the CPU usage also decrease, but I can’t to that since my application relies a lot on the taskMgr.
Is there a way to decrease this CPU usage when nothing is displayed (or when the display doesn’t change), cause on a laptop, it will help to save batteries.

Thanks in advance.

You can do this by setting the yield-timeslice PRC variable to #t.

I tried and it didn’t change anything :confused:

edit : in fact it works if I remove the code setting the fps.

You could set the client-sleep variable to a low value, to let Panda wait a small number of milliseconds every frame.

But by doing this, It will also decrease the performance of my other task in my application :question:. The execution will be slower. :frowning:

With the yield-timeslice properties, no fps set and base.win.setActive(False), it’s still using 8% of my CPU doing nothing. :exclamation:
Setting client-sleep to 0.01 make the CPU usage falls to 0% :slight_smile:

I tried something else, just to see. I did the main loop with gtk and call TaskMgr.next() each 15 ms. When I set base.win.setActive to False, my CPU is at 0%. :slight_smile: Everything seems to works except when I have a complex scene in my application, the FPS falls to 30fps, while it was still 60fps with the panda main loop. :confused:

Does this still show if you disable vsync, with “sync-video” set to “#f” ?

Yes, no change on the cpu. (except of course when I set base.win.setActive to True.)

Hm, there is also another thing weird.

If I set sync-video to True, I’m at 60 fps and my CPU is using 6%. But if I set sync-video to False and I set clock-mode to limited and clock-frame-rate to 60, I’m at 60%.

In both case I’m running at 60fps, but one is using 6% of my CPU while the other uses 60%.