Calling taskMngr.step() takes too long to return

I am working on a physics simulation framework in python which calculates rotations and positions of objects in a scene per frame. I am trying to visualize this through Panda3D. I had no problem loading the models in the scene and changing their states according using to the parameters of the framework. I also implemented an update function which rotates two of the models with each call. The delta time is also dictated by the framework since the intensity of the movements has to match the desired framerate. This means that the framework calculates the appropriate parameters for each frame and I retrieve these values in the update function and change the model state accordingly. Because of that taskMgr.step() has to be called by the framework for each frame and I can’t use the main loop because it blocks the operations of the framework. I only have this update function in my taskChain. The problem now is that executing the task once through step() takes longer to return than the needed framerate which leads to the whole animation running in approx 6x slow-mo. I tried changing the ClockMode, setting dt and framerate within Panda but none of that has any effect. Even tough the frame-rate-meter shows different values after that, the animation has the same speed. I also checked if I had any performance issues because of too many objects or similar but even if I create an empty showbase and leave the update function empty it takes the same time. Not calling taskMgr.step() on the other hand leads to the desired performance but then I obviously do not have any output. What can I do about it?

Hi, welcome to the community!

You could consider enabling the multi-threaded render pipeline, which will make Panda perform the rendering in another thread. Or, you could consider running the other framework in a different thread.

Also consider whether VSync is on, which will make each frame wait for the vertical blanking interval of the monitor.

Hi, first of all thank you for the quick answer! Sorry for my late response but I wanted to try around with your suggestions a bit before coming back to you. Multi-threading is still a little overwhelming for me but I am currently reading into it.
Concerning the other suggestion I noticed something new. Although I wrote “vsync 0” and “sync-video 0” in the config.prc I ended up with 60fps. Then I used another monitor with 144Hz and had 144fps. I concluded that my graphics driver overwrites this setting and forces vsync. I found out how to disable it in the driver on Arch Linux and got 250-300 fps. I guess there is now way to force disable vysnc within panda so that not every user has to disable it by hand?
Also I would technically need 500 for my use case. Do you think that this performance can still be improved (without multithreading) since my GPU is barely loaded or should I stick with the 250-300 fps and reduce the temporal resolution of my framework?

Thanks a lot!

Also after disabling vsync in the driver, setting vsync on in panda has no effect anymore.

About the sync problem, see this issue on git : VSync does not work on Linux with NVidia drivers · Issue #963 · panda3d/panda3d · GitHub

The current workaround is to set a couple of environment variables to override the default mode of the driver.

Enabling the multithreaded pipeline in Panda is just a matter of flipping one config switch (threading-model); it doesn’t require you to use multithreading in your application.

Thank you both for the answer. So I guess the vsync problem has to be mentioned in the manual of my framework then. And I thought I needed to tweak more parameters for multithreading but Cull/Cull seems to result in ~50fps increase :+1: