[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 488: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/bbcode.php on line 112: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4762: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4764: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4765: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
[phpBB Debug] PHP Warning: in file [ROOT]/includes/functions.php on line 4766: Cannot modify header information - headers already sent by (output started at [ROOT]/includes/functions.php:3897)
Chipmunk Physics • View topic - How much is Chipmunk faster then Pymunk?

How much is Chipmunk faster then Pymunk?

Official forum for the .

How much is Chipmunk faster then Pymunk?

Postby faiface » Sat Mar 16, 2013 11:27 am

Hi!
I'm developing a game in Python 2.7. It'll be 2d parkour game with physically simated stick figure. But I have a problem. I have created classes like Stick, Torso, Head, Joint (but in Slovak language).
Head is of course basic circle.
Torso is made from multiple Sticks.
Stick is made from basic Polygon.
Everything is connected with Joints.
Joint is made from PivotJoint (to connect) and GearJoint (to rotate).
But when I connect everything to make a basic stick figure (generally 1 head, 12 sticks and 11 joints) the FPS is maximum like 60-70, and that's really not enough (when there will be a complete level I can't even imagine how low will it be).
I want to ask if I should write all this as an extension for Python in Cython and use a basic C version of Chipmunk in it. Will it improve FPS enough?
faiface
 
Posts: 7
Joined: Sun Feb 24, 2013 2:52 pm

Re: How much is Chipmunk faster then Pymunk?

Postby slembcke » Sat Mar 16, 2013 3:04 pm

Pymunk is just a wrapper of the C code. 99% of the work it does is running as C code. You should be able to run thousands of bodies/joints simultaneously. Pymunk is probably not the problem.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: How much is Chipmunk faster then Pymunk?

Postby viblo » Sat Mar 16, 2013 3:48 pm

First of all, you should really profile your code to locate the bottleneck(s). Only when you have done that should you start to think about what to do about the problem. When you have located your problem can give you better suggestions about how to improve the performance and if cython would help.

Anyway, in general there are 3 areas where the bottleneck of your performance can be:

1. Somewhere in your code not related to pymunk
In this case it might help with cython in the slow parts. Not to rewrite the pymunk binding, but because python code compiled with cython generally become quicker if tweaked correctly. You can also try other things such as using Pypy instead of cPython. However, the best is usually to first try and improve your code, use better algorithm and so on.

2. In pymunk / the bridge to chipmunk
In this case it will probably help with cython. Ctypes adds a little bit of overhead. Another option you could look into is to wrap with cffi which at least on pypy probably would give you a good speedup while still being a python library.

3. In chipmunk
If the bottleneck is in chipmunk itself it wont help what you do in python land.

Given the information in your post I suspect that the performance problem is not in pymunk nor chipmunk but somewhere else in your code. The platformer demo that is included in pymunk runs in 800 fps on my computer if I turn off the fps restriction.
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm

Re: How much is Chipmunk faster then Pymunk?

Postby faiface » Sun Mar 17, 2013 6:26 am

faiface
 
Posts: 7
Joined: Sun Feb 24, 2013 2:52 pm

Re: How much is Chipmunk faster then Pymunk?

Postby viblo » Sun Mar 17, 2013 3:56 pm

Interesting about your max fps.. I tested on my stationary which is almost 3 years old, but contains gaming stuff. Now I reran it on my other computer, a laptop about 2 years old similar to a macbook air in performance and got around 200. Much bigger difference than I thought I would get for this type of test.

To investigate a profile I usually sort it by cumtime and tottime and then look at the top 5-10 entries depending on how much each entry contribute.

If we sort by tottime (which is time spent in a function excluding calls to sub functions), you will find that the top entries are display.flip() and display.set_caption() with 0.4 sec each. flip we cant do anything about, we need to flip the screen. But you could rewrite the code to not update the caption every frame, should be enough once every second :)

If we instead sort by cumtime (time spent in a function including calls to sub functions), you will find that most time is spent in your main method. This is of course nothing strange. Next entry is the draw_space method, a whole 1.2 seconds is spent in there. The pymunk pygame drawing methods are really not that optimized and is mostly intended for debugging and prototyping easily. They redraw everything each frame, that is not the best way to draw with pygame (but the easiest).

With this info I suggest you try and run without drawing to get an estimate on how much time is spent drawing (for example, add a button to toggle drawing). When you have an estimate maybe you should investigate how to optimize the drawing part of the code. Either implement your own drawing in pygame, or use something else like pyglet instead.

I also have two small suggestions on profiling:
Its usually a good idea to sort the output to have it easier to read. Otherwise you more or less have to paste it into something else for sorting (I copied your output to excel). I often use the sorting found in balls_and_lines.py demo, but it is usually a good idea to sort it in other ways as well to find the easiest to improve spots.

I also like to run the program for a little bit longer, like 20-30 sec. Usually I run quicker iterations for just a few seconds like in your case, and then longer runs to easier make sure startup and loading code doesnt show up in the profile.

Edit: I tested to remove the call to draw_space in the platformer demo and the fps on both my computers doubled..
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm

Re: How much is Chipmunk faster then Pymunk?

Postby faiface » Sun Mar 17, 2013 4:50 pm

Alright, so I just tried to run without drawing.
When I just removed draw_space, fps got higher by 30-40%. When I removed all drawing including pygame.display.flip(), and just printed fps, I got around 200 which is almost 4x more than with all drawing.
I also tried to do the same with platformer and I got around 1000 FPS, so my game is 5x slower.
But I really cannot find out what's wrong with my code.
One "maybe solution" would be to switch to pyglet.
Or should I send you my code?
faiface
 
Posts: 7
Joined: Sun Feb 24, 2013 2:52 pm

Re: How much is Chipmunk faster then Pymunk?

Postby viblo » Mon Mar 18, 2013 5:36 pm

My experience is that to have quick drawing in pygame you need to not redraw so much of the screen each frame, each pixel draw costs a little bit, a 2x2 square is much less expensive to draw than a 100x100 square. Using OpenGL (for example with pyglet) its more or less free to draw a pixel meaning a 2x2 square is as expensive as a 100x100 square. However, each draw call is expensive, meaning its more expensive to draw 50x100 twice than 100x100 once.

This also means that pygame is much more sensitive to the resolution (drawing 1920x1200 pixels is much much more expensive than 640x480 for example).

Another thing to remember is that pyglet/OpenGL drawing depends in a large way on your graphics card while pygame uses mostly cpu power for drawing. So a computer with a slow graphics card (such as lightweight laptops and old computers with no external card) will probably be better at pygame than pyglet.

But I dont have so much experience with optimizing pygame drawing. I usually use it for small experiments/prototypes because its easy and very widespread, but in the last couple of full games (where performance matters) I used pyglet. Maybe you could try and post to the pygame mailing list? (and/or do an experiment with pyglet)
http://www.pymunk.org - A python library built on top of Chipmunk to let you easily get cool 2d physics in your python game/app
viblo
 
Posts: 206
Joined: Tue Aug 21, 2007 3:12 pm

Re: How much is Chipmunk faster then Pymunk?

Postby faiface » Tue Mar 19, 2013 9:27 am

I've just rewritten that to Pyglet and the performance increased very much. Thank you for your time helping me :). I really don't know why is PyGame so slow on my computer, but Pyglet is just ok so I will continue my game development with it.
faiface
 
Posts: 7
Joined: Sun Feb 24, 2013 2:52 pm


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests

cron