[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] pygame slowness



I think you need to change the way you do things with your objects.

See this for reason why you should change your api around if you need
performance.
http://rene.f0o.com/mywiki/BatchingApis


As well as reducing function calls, consider using things like map,
filter, and zip instead of for loops.

Also see this page for how to use the hotshot profiler which will show
you c extension functions like blits.  I think you may get different
profile results.
http://www.pygame.org/wiki/Profiling

Have you tried it out with psyco?


If you can show people the code you will get lots better advice.  For
other peoples games, I have seen them go 4 times as fast with a few
tweaks to different functions.




Good luck!




On 12/16/05, Lionel barret De Nazaris <lionel.bdn@xxxxxxx> wrote:
> Hello all,
> my game (a cross between a shoot them up and gauntlet) is running so
> slow that i consider abandoning python and pygame (at least for display
> and collision detection).
> I would be very grateful if anybody could lend a hand to help and avoid
> this, I really like Python.
>
> The heart of the problem in the rendering sub-system. Of 18 sec of play
> time, 15 of them are spent rendering.
> Here follow a short description of the rendering process :
> Each iteration of the main loop,
> - the Event Manager is called and launch the callbacks linked to the key
> pressed,
> - the World update itself : each World Object update itself (i.e move,
> shoot and die)
> - the Camera update the rendering :
>     - update it own position in World Coordinates relatively to the
> World Object it follows (the player's ship)
>     - calculate for each World Object, the screen position of the image
> linked to the World Object and blit it.
>
> This seems quite reasonable but I get only 15fps. And the frame rate
> drop as I add World Objects.
> My level are quite empty (around 100 objects, including bullets) and I
> am afraid that later in the production phase, the engine will be simply
> too slow to add all the nice things we have in stock.
>
> According to the profile, the main culprit is the Camera Update, but i
> don't think it's possible to avoid doing calculus for each World
> Object..So i am quite lost. (Sigh...)
>
> (I joined the profile report to this mail, if you want more details.)
>
> --
> Lionel Barret De Nazaris
> =================================================
> Gamr7.com > http://www.gamr7.com
> Gamr7's Blog > http://creatinggames.blogspot.com/
>
>
>
>
>
>
>
>          518616 function calls (516926 primitive calls) in 10.248 CPU seconds
>
>    Ordered by: internal time, call count
>    List reduced from 209 to 50 due to restriction <50>
>
>    ncalls  tottime  percall  cumtime  percall filename:lineno(function)
>     72887    1.363    0.000    3.807    0.000 camera.py:36(updateVisualRessource)
>     72887    1.054    0.000    4.860    0.000 camera.py:54(<lambda>)
>     25771    0.986    0.000    2.099    0.000 VisualRessource.py:143(update)
>     29543    0.674    0.000    0.860    0.000 VisualRessource.py:108(draw)
>       532    0.573    0.001    5.433    0.010 camera.py:21(updateVisualRessourcesFromWorldObjectPosition)
>     26600    0.514    0.000    1.409    0.000 ressmanager.py:52(<lambda>)
>     25771    0.511    0.000    0.931    0.000 VisualRessource.py:59(updateVisualRessourceInstanceIFN)
>     26600    0.387    0.000    0.670    0.000 ressmanager.py:64(<lambda>)
>     26600    0.348    0.000    0.895    0.000 layer.py:22(updateAndDraw)
> 26071/25761    0.312    0.000    0.312    0.000 VisualRessource.py:48(isAnyChildModified)
>     26600    0.283    0.000    0.283    0.000 layer.py:31(clear)
>       532    0.282    0.001    8.119    0.015 VisualRessourceManager.py:48(update)
>       532    0.216    0.000    0.886    0.002 VisualRessourceManager.py:61(clear)
>     25573    0.186    0.000    0.186    0.000 VisualRessource.py:179(getVisible)
>     25771    0.183    0.000    0.183    0.000 VisualRessource.py:104(getIndexOfClippingRectList)
>     10801    0.170    0.000    0.170    0.000 VectorMath.py:19(dotProduct)
>      1345    0.156    0.000    0.387    0.000 collisionmanager.py:90(getWhenPointInRect)
>       315    0.150    0.000    0.994    0.003 collisionmanager.py:149(getFirstLTCollidedWith)
>      1260    0.146    0.000    0.424    0.000 collisionmanager.py:27(getCaseCrossdByVector)
>      2400    0.133    0.000    1.379    0.001 WorldObjectpy:126(update)
>      5204    0.098    0.000    0.098    0.000 VectorMath.py:99(getIntersectionOf2Segment)
>      5788    0.077    0.000    0.122    0.000 world.py:70(world)
>        72    0.068    0.001    0.069    0.001 collisionmanager.py:221(LTAround)
>      2387    0.066    0.000    0.170    0.000 WorldObjectpy:94(IsInWorld)
>      1846    0.063    0.000    0.086    0.000 camera.py:84(camera)
>      1490    0.051    0.000    0.469    0.000 actors.py:82(update)
>      2684    0.048    0.000    0.136    0.000 collisionmanager.py:99(getVectorOfColl)
>      5788    0.045    0.000    0.045    0.000 world.py:64(getInstance)
> 2453/2387    0.045    0.000    1.070    0.000 WorldObjectpy:46(move)
>      3021    0.045    0.000    0.409    0.000 layer.py:26(<lambda>)
>       379    0.045    0.000    0.987    0.003 actors.py:173(update)
>       532    0.042    0.000    0.042    0.000 camera.py:72(clear)
>      2400    0.042    0.000    1.708    0.001 world.py:46(<lambda>)
>  1998/894    0.040    0.000    0.221    0.000 effet.py:42(update)
>       379    0.040    0.000    0.059    0.000 ressdesclibrary.py:87(CreateOwnRessourceInstance)
>       379    0.034    0.000    0.180    0.000 actors.py:136(update)
>      1260    0.034    0.000    0.049    0.000 collisionmanager.py:22(getCaseContainingPoint)
>         1    0.032    0.032   10.248   10.248 main.py:18(main)
>      2682    0.029    0.000    0.029    0.000 collisionmanager.py:115(<lambda>)
>       532    0.027    0.000    0.248    0.000 effet.py:10(update)
>      4020    0.027    0.000    0.027    0.000 VectorMath.py:67(vectorFromPoint)
>      1846    0.023    0.000    0.023    0.000 camera.py:78(getInstance)
>       532    0.021    0.000    1.729    0.003 world.py:43(update)
>   666/656    0.021    0.000    0.109    0.000 VisualRessource.py:36(CreateRessourceInstance)
>       674    0.021    0.000    0.042    0.000 VectorMath.py:57(Normalize)
>      2520    0.021    0.000    0.021    0.000 collisionmanager.py:42(<lambda>)
>      2690    0.020    0.000    0.020    0.000 collisionmanager.py:95(<lambda>)
>      3094    0.020    0.000    0.020    0.000 log.py:7(log)
>       532    0.018    0.000    0.090    0.000 eventmanager.py:4(dispatchKeyboardEvent)
>       778    0.017    0.000    0.039    0.000 collisionmanager.py:143(getTimeOfCollision)
>
>
>