It’s a weird issue, and one I didn’t know what to make of.
So I’ve programmed the same small program in C++ and Python and am comparing the two in speed. The C++ copy is proudly displaying its ridiculous speed by giving me a wall of gray representing ~16ms of wait instead of processing time on pstats; however, the Python version is doing something quite weird… as the “game” continues to execute, pstats reports incrementing time used by “Bounds”. The program starts out performing sort of close to the avg. performance of the C++ version but after about 30 seconds, I’ve gone from 60FPS to <30FPS and if you watch it go, it continues to go downhill from there (I’ve watched it go into the low 'teens but got bored after that).
So, I’m wondering, first of all, what does pstats mean by “Bounds”? My first guess was something to do with bounding boxes but after further thought I don’t think that’s totally correct.
Do you mean “:Bounds", that is, “Bounds” within the "” category? That is indeed the time Panda spends recomputing the automatic bounding volumes. If it’s increasing steadily, perhaps you’re leaking nodes or something like that–is the number of nodes also increasing?
Yeah, using render.analyze(), it’s showing me that I’m leaking nodes, and after a bit of looking I’ve found the problem. I was creating nodes in a looping task … which obviously isn’t optimal. As soon as I get it cleaned up it should be working fine.
I didn’t want to make another thread because this is related to the same program.
So I made the change and am no longer getting node leakage but the Python version is till running only at a ~66% of the speed of the C++ version and I don’t think that it’s because it’s written in Python because this time, the culprit is large sporadic Waits in the form on Thread Blocks according to PStats. I actually turned off vsync in the config.prc so the program really shouldn’t be doing much waiting, should it, as I’ve told to render the next frame as fast as bloody possible?
Hmm, that’s interesting. “Thread block” refers to time spent waiting for another thread (or another process) to complete. If you aren’t running any threads yourself, large amounts of “Thread block” time is usually due to the operating system scheduling other processes.
My guess is that this is due to an explicit sleep() call in ShowBase.py, which isn’t present in the C++ equivalent (or some similar difference). Try setting these variables in your Config.prc to ensure there is no redundant sleep:
I did what you said and added the three vars as 0 but nothing changed. After that, I even went into ShowBase.py and commented out the setSleep() subroutine but still nothing… So, it seems that a sleep call isn’t the problem but I’m still getting these thread blocks and ONLY on the Python version… which is, as you said, very interesting.
Hey, that actually fixed it. Python version is still running slightly slower than C++ but at least I’m not getting those thread blocks.
So, onto another question: Is it possible to export the data that PStats obtains? As, is it possible to output the graphs, the data or perhaps even obtain a min/max/avg frame value from it? Or would I just have to code that myself in the program?