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

Re: [pygame] pygame slowness



Thank for all the feedback,

I'll try to set up a repository to show the source code. I'm a bit shy about it, because I try to set my own company and i feel it's a little
like making the community work for my profit. As long as I am starving (like now), I suppose this is OK. ;)


About the Python function calling, i know this is supposed to be slow, but I didn't know it was *this* slow.
Something I really miss is a hierarchy of slowness of the python call (local, self.attributes, globals, module, lambda, etc).
This would give hint about what to do in the critical part of an application, specially a game.


I'll sort of try to test by upping the number of object , but the results where not clear.
Obviously, some parts scale in log , other may be linear.
Anyway, I will dig this a bit deeper, turning off some subsystems.


<rant on>
By the way, I looked at the source code of many pygame games, I felt they were they were not very structured.
I mean no offense (after all these games run far better than mine), but I am afraid that my style may be too structured (or too abstract) for python.
I know that "flat is better than nested" but I think that "simple is better than complicated", and to make things simple, you need to create abstractions.
In a game that could mean many abstractions.
<rant off>


Sorry, for the rant, it has been a very long day.

Guillaume Proux a écrit :
Difficult to help without more information and source code.

First thing... you seem to have MANY MANY function calls and lambda functions
... Python function calling is well known to be slow.
Try to unroll some of your most inside loop and in this loop make sure
that all object you are accessing have a local binding.

Then you can try to use some more helpful optimizations
I have managed to multiply by 10 the speed of a complex parser I had
written by going into each function that was too long and making sure
it was not doing something foolish...

Sometimes you might find out that in a loop you end up retraversing
every time a long list...
Check what happens if you multiply your number of object by 10 in your world.
If the system goes 10 times slower, then there is some limiting factor
on the per object basis. If it goes 50-100 times slower... Worries. it
means that you are doing something expensive in a loop that runs
square to the number of objects in your world


Regards,

Guillaume

-- Lionel Barret De Nazaris ================================================= Gamr7.com > http://www.gamr7.com Gamr7's Blog > http://creatinggames.blogspot.com/