Pygame games actually spend very little time running python code. The vast, vast majority is spent on SDL fill and flip operations. Most fill not needed. How important is it? Well, take my computer. Let's say you are writing a game in which there is a loop that simply draws the background in one color. It will receive about 40 frames per second. This is because it is mainly suitable for each pixel individually and is written to it. This uses 200 x 300 = 60,000 operations per frame to do nothing.
So, instead of painting the whole background, just draw the parts that were drawn on the previous frame.
This makes your code a bit more complex, but it gives a huge increase in performance.
Also, be sure to run cProfile to find out where the problem areas are. Look, don't guess.
source share