Python - sudden slowdown in Pygame

I am writing a 3D engine in Python using Pygame. For the first 300 or so frames, it takes 0.004 to 0.006 seconds to render 140 polygons. But after that, it suddenly takes about 0.020 seconds on average to complete the same task. This concerns me because this is a small test, and although 50 FPS is decent, it cannot be supported on 1000 polygons, for example.

I have already done a lot for my code. I also did some deeper profiling, and it seems that the increase in time is more or less proportionally distributed, which suggests that the problem is not related to one part of the code.

I am guessing that the problem has something to do with memory usage, but I am not sure exactly why this problem is happening. What specific problem is causing this, and how can I optimize my code to fix this, as well as some more general methods? Since my code is very long, it is posted here .

+3


source to share


1 answer


While I can't answer your question exactly, I would use the task manager and watch the "python" (or "pygame" process depending on your OS) and look at its memory consumption. If this turns out to be a problem, you can check which variables you donโ€™t need after a certain time, and then you can clear those variables.



Edit: Some CPUs have data loss prevention systems. What I mean is this: If Application X takes up 40 %% CPU (it shouldn't be that high). After a certain amount of time, the CPU will throttle the amount of CPU that Application X can use. This can cause slowdowns for things like this. This does not happen with (most) games, because they are tuned in to tell the processor to expect that voltage.

+1


source







All Articles