Pygame slowness :(
Added by John Lyon 172 days ago
So, it looks like I've already hit the old pygame slowness wall. It was always going to happen as I'm using an eeepc, but considering we only have a few objects on screen, it's going to be an issue. I've run a profile to confirm that all of the time is spent in blit:
Tue Mar 16 19:52:21 2010 profile.txt
3337 function calls in 4.908 CPU seconds
Ordered by: cumulative time
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.020 0.020 4.908 4.908 game.py:85(run)
1 0.000 0.000 4.908 4.908 profile:0(game.run())
1 0.000 0.000 4.908 4.908 <string>:1(<module>)
603 0.040 0.000 4.468 0.007 /home/john/Machine/Machine/entity.py:13(draw)
603 *4.428 0.007 4.428 0.007 :0(blit)*
402 0.016 0.000 0.664 0.002 /home/john/Machine/Machine/entity.py:26(draw)
67 0.188 0.003 0.188 0.003 :0(fill)
14 0.000 0.000 0.180 0.013 /home/john/Machine/Machine/asset.py:26(load)
4 0.180 0.045 0.180 0.045 :0(load_extended)
335 0.008 0.000 0.008 0.000 /usr/lib/python2.6/dist-packages/pygame/sprite.py:152(update)
210 0.008 0.000 0.008 0.000 :0(colliderect)
I'll now be looking at porting everything to pyglet, which uses opengl and is apparently much faster. In the meantime, keep hacking!
Replies
RE: Pygame slowness :( - Added by Matthew Bowra-Dean 172 days ago
That's unfortunate, it's been a while since I've tried out Pygame. I had hoped they would have fixed the perf issues. It leads me to believe that everyone recommending it has never used it themselves when it has such low constraints.
Using OpenGL should be simple though for 2D stuff.
RE: Pygame slowness :( - Added by John Lyon 172 days ago
If anyone is interested in tinkering with pyglet, there's an easy to understand asteroids clone written with it here http://github.com/irskep/pyglettutorial
I'll be attempting to port what we have to pyglet shortly and will see how that affects performance.
There are probably some things we could do to speed up pygame (no alpha blending, use dirty rects when the background isn't scrolling) but it's a bandaid on a broken arm - pygame just can't do fullscreen blitting quickly. Pyglet looks just as easy to use from what I've seen so far.