Coder Social home page Coder Social logo

Perf improvements about chipmunk2d HOT 5 OPEN

viblo avatar viblo commented on June 7, 2024 1
Perf improvements

from chipmunk2d.

Comments (5)

slembcke avatar slembcke commented on June 7, 2024 1

Yeah... Like there's a lot I want to do to modernize Chipmunk. At this point it's 17 years old! Like there's a lot of data changes I could do to vastly improve performance, and the whole API itself could use a pretty big "modern C" upgrade. On the other hand I have 2 big projects for work, and a host of other hobby projects. :( I just don't see myself being able to pull that off without making something much simpler and more focused like the physics I made for Veridian Expanse. On the other (other) hand, Erin Catto has been working towards Box2D 3.0, and it's absolutely a wishlist of everything I would put in a Chipmunk refresh. Modern C API (not C++!), heavy multi-threading focus from the start, object handles instead of direct pointers, etc. It sounds pretty great.

Pymunk for research: That reminds me! Not sure if I shared this story with you before. A few years back I helped mentor high school students for the FIRST Robotics competition. One of those students is now getting his PhD in robotics actually. I ended up sitting next to him at a LAN party of all places and we talked a lot about game tech. He didn't realize that I worked in games, and I mentioned a bunch of our projects including Chipmunk. Apparently he used Pymunk in his PhD research to do his initial simulations to develop the control systems they were working on. Small world! :) I don't think I've said this in a while, but it's awesome that you made Pymunk. It really seems to help a lot of people.

GPU acceleration: Not really. I've read a bit about how people have approached some of the algorithms involved, but that's about it. I think realistically Chipmunk's OO-ish API is a terrible fit for how GPU accelerated data needs to be organized and you'd need to copy a lot of data around. I've done just enough related work too to know that there are a lot of subtle mistakes you can make when trying to optimize at that level that can destroy performance too.

from chipmunk2d.

slembcke avatar slembcke commented on June 7, 2024

Hrm. So I've known for a while that a number of my early decisions in Chipmunk were fairly sub-optimal. In the past I did experiments where I rewrote large sections of Chipmunk to be SoA ordered data, and that helped a lot. The problem is that a lot of those structs are part of the public API and I can't really change them now. I'd never really considered the impact of just reordering fields though... I'm kind of surprised that inlining the contacts into the arbiter helped as the contacts are already linearly packed into memory in the order they are accessed. I've considered Chipmunk to be "stable" for quite a few years now where I don't really have any big or breaking changes to make. I'm not sure how I feel about this, but could maybe be convinced. I certainly wouldn't mind if you made a "turbo" fork or something.

I'm currently making a new game, and I actually wrote a new (but very very simple) physics engine for it to finally try out some new ideas. It's vaguely ECS based, and it heavily uses SoA. I knew it would be faster, but I was shocked to find it running several times faster. (Though it's hard to make a very direct comparison) https://github.com/slembcke/veridian-expanse/blob/master/src/drift_physics.c Anyway... not really relevant, but it's interesting to think where Chipmunk could go in the future.

from chipmunk2d.

viblo avatar viblo commented on June 7, 2024

I was also surprised that I got a clear effect from my very limited changes, especially for just rearranging stuff which is easy and safe to do (unless you care about binary compatibility of course). I can see your desire to keep it stable. I have had some user complain when moving from Pymunk 4.x to 5.0 which broke several things and its a difficult tradeoff. At least its better its stable than things changing for the worse, or more bugs etc are introduced.

One thing Pymunk is used for is different kinds of research (maybe this is even the most common usage). Its an quick and easy way to simulate an environment and then try different things (for example reinforcement learning, motion prediction and a lot of other stuff).

Some years ago I had a discussion about future of Pymunk with some toolkit for developing AI algorithms (i.e. simulate an environment for a robot and other stuff). They were using a python library built on top of Box2D, which was not maintained.
One thing I think they cared about were simulation speed which becomes extra important if you want to re-run the same simulation many many times to train an algorithm. In the end I think they went with a different path and uses something else that have more big-company support and can be accelerated on GPU. Anyway, my point is that for example for (python) games I think Pymunk/Chipmunk is often fast enough, other things will limit. But for these other cases I think there's lots of room for faster simulation speed.

Now, I just do Pymunk dev sometimes in the evening, so if I really will be able to make some breaking big performance improvements is still to open. If nothing else I will make a PR of rearranged structs, but needs some more test to see what was useful first.

from chipmunk2d.

viblo avatar viblo commented on June 7, 2024

Btw, have you looked at GPU acceleration of Chipmunk? Or maybe its not really relevant for games when the GPU is busy doing graphics anyway?

from chipmunk2d.

viblo avatar viblo commented on June 7, 2024

Yeah, the lack of time/focus is always a biggie. There's so many things that would be interesting to try! This is also why I made the post here in the first place, best to share the small thing while its fresh, even if nothing more is done..

Small world indeed :) As always, cool to hear about someone using Pymunk!

GPU: Ah, yeah that is what I guessed. Difficult/impossible to shoehorn into an existing design, and it can have wide-ranging side-effects.

from chipmunk2d.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.