[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[pygame] Pygame and Psyco
hey everyone, i've been playing a bit with pysco to see what it can do for
pygame games. the good news is, psyco can have a huge speed boost. the
not-so-good news is, it's not going to help everyone.
at this point there are a couple packages for python that promise speeding
up python code. the thing i like about psyco is it requires no change to
the python game. with a simple try:except: block, your game could get the
extra speed for people with psyco, otherwise it will run as normal python
speed for those without.
basically you just 'import psyco' and then tell it which functions you want
it to optimize, and you are all set. because psyco takes a big chunk of
memory, you mainly just optimize the parts of the code that are your
bottleneck.
the first thing i did was to hook up the pygame sprite library to psyco,
and test it with a fairly sprite intensive benchmark. (making good use of
many of the different classes and collide functions). unfortunately there
was barely 1 or 2 fps difference between them. i was pretty disapointed. i
determined that even with the program running faster, most of the program
was drawing graphics, which isn't going to get any faster. using a special
version of the sprite library with a dummy "blit" function i noticed that
psyco made the program about 20% faster, 700fps to 900fps.
then i decided i wanted to test some code that wasn't bottlenecked by
graphics. i remembered that Jeroen was a little frustrated with the speed
of the AI in his game "4st attack". i cranked up the AI to look 5 moves
into the future, and noticed it took around 26 seconds for the ai to make
each move. i imported psyco into the ai module and reran the test. it now
takes almost exactly 2.6 seconds to compute each move. (argh the AI is way
too hard at this point)
wow, i am still very impressed 10x speedup and i didn't have to change
anything. this is the first 'python speedup' type thing i've tried that
actually made any difference. i've played with "python to c" code
converters and other sorts of optimizers, but nothing ever really gave me
noticeable speedups.
well that's good news. worth anyone's time who is trying to get more speed
out of 'fat' parts of their game. of course it will always be tricky when
optimizing. you'll need to point psyco at parts of the game where 'python'
is the actual bottleneck. it seems mainly in pygame games the most serious
bottleneck is in the software graphics. but games with complex ai, physics,
or object management may see similar benefits from psyco.
again, the coolest part is you don't have to change any of your code. your
game will run with or without the user needing psyco. the psyco website is
at http://psyco.sourceforge.net/ . also i've "cross-spammed" the author
with this email, so if you have any questions for him as well, reply-all
may catch his attention ;]
oh, and i hope that means we'll be seeing a new version of 4st attack
someday sooner than later :]
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org