Jondolf / avian

ECS-driven 2D and 3D physics engine for the Bevy game engine.
https://crates.io/crates/avian3d
Apache License 2.0
1.44k stars 115 forks source link

Performance - Time to optimise? #319

Open dror-g opened 8 months ago

dror-g commented 8 months ago

Hello, first I'd like to thank you for this amazing crate! You're doing such a great job.

More of an opinion / suggestion than an issue, but I think it might be time to focus on performance rather than adding features.
Bevy_xpbd is becoming very popular, and gets mentioned whenever physics come up, and is able to address most use-cases.
With its tight Bevy integration it very easy and convenient to use.

But - there is a big performance gap between it and Rapier.
For me, on low-end Android devices and Wasm, xpbd struggled with 100-200 constantly colliding entities, even with just 2 substeps.
Rapier can handle +1000 entities.

Perhaps it's time to adjust priorities?

Thanks again for your amazing contribution!!!

mattlennon3 commented 8 months ago

I was just coming here to write a similar issue. The move-marbles example is a fairly sluggish 30fps for me while moving them around. I am researching libraries to implement something like this fluid simulation, which seems to have excellent performance with vanilla JS in a web browser. There are significantly more entities in that simulation too.

Thanks again for your amazing contribution!!!

I would definitely echo this, I am not trying to throw any shade on the developers here. This library seems really great already, just lacking in performance right now. Thanks 🙏

Jondolf commented 5 months ago

This has been sitting here for a while now; apologies for not leaving a proper response sooner.

This is clearly a very important issue to address, and definitely one of the areas where bevy_xpbd is severely lacking in comparison to Rapier and many other physics engines.

I'm in the process of a major rework of the solver and a lot of the other internals (see #346, although it's slightly outdated at this point). It will hopefully be ready and released in roughly a couple of weeks. The new version only runs narrow phase collision detection just once per frame instead of once per substep, and is also more stable in general, which should improve performance for collision-heavy applications quite significantly (about 3-5x fps in some tests, but results may vary).

After that, I plan on opening a bunch of issues for further performance improvement work, as well as a tracking issue. Some big things include:

Simulation islands will probably be the first big improvement I plan on working on after the upcoming release, along with one-body contact constraints (which should be pretty trivial) and some smaller miscallaneous performance work. Other things like graph coloring and SIMD constraints might take longer, but I'm interested in trying to implement them as well.

In short, I acknowledge that the current performance frankly sucks for physics engine standards, and I really want to improve the engine in this regard. The new solver should hopefully address some collision performance issues, but there will still be a lot of follow-up work. I will lay this out in more detail in issues after the upcoming release.

dror-g commented 5 months ago

The new version only runs narrow phase collision detection just once per frame instead of once per substep

Amazing! great to see these small high-reward fixes. great work finding these!

Use par_iter in more systems in general (position integration, CCD, constraint preparation)

Sounds like good first-issues for contributors!

I have very high confidence in this project, given your priorities and roadmap. Well done!