Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Physics Engine 13x Faster than Matter.js (github.com/altanis)
29 points by altanis on Aug 29, 2023 | hide | past | favorite | 14 comments


I recently created a physics engine for all sorts of convex entities which, when benchmarked against many other popular engines such as Matter.js and Planck.js, outperformed them effortlessly. I would appreciate if you guys checked it out, as it took me a long time to complete it! https://github.com/Altanis/kinetics-ts.


Demos would probably be nice to add to project's front page. Right now, you're trying to sell on numbers alone, but making a demo that shows the other libs are actually slower would work so much better.


I have a demo on the website.

https://kinetics.vercel.app/docs/demo

I benched the results without rendering (more or less focused on backend game physics), I'm not sure how it'd work with rendering since FPS lag would probably hinder performance to the point theyre both equal. In the event someone wants to make my library more efficient with rendering, they can always use WebGL with WASM


Nice! What is the intended application?


Any applications for 2d physics, for example simulations and games and whatnot.


Thank you guys so much for the support! I could never dream of 20 stars, let alone 100!


Good work, Altanis! After exactness, speed is certainly a priority. For my engine, I settled on Rapier, which also offers excellent performance (and determinism!). Do you think you could compare it with Kinetics?

Can you provide a high-level view of how you achieve that speed? I have also heard of eXtended Position-Based Dynamics as one of the latest improvements in physics engine. Do you have a perspective on that?


I will bench Rapier against Kinetics in a few minutes and upload results to GitHub. I'm sure it's much faster though, it uses Rust

As for the speed the engine provides, not much. I just optimized my spatial hashgrid. It used to iterate over every entity, found the cell it was in, and checked the objects in that cell. I replaced it by iterating over each cell, and checking the entities in the cell. Performance went up significantly (iirc 1k squares took around 6-7 mspt, now its 0.4mspt)

The engine actually uses position based dynamics (the penetration depth changes position), as for extended position dynamics, I looked into it but "softness" isn't a field in the entity object, so I decided to not implement it (extended pbd iirc just fixes softness)


I'd say a good start, but it is still quite a simple implementation and I think thats where any performance gains come from.


Definitely! I am not discrediting Matter.js, it is incredibly accurate and has a bucketload of features. kinetics.ts is meant to be a minimalistic engine primarily for basic 2d games (take io games for instance), and for that it performs quite well in comparison to matter.js


Do you support linkages and constraints? That's where game physics gets hairy. Ideally, you'd have a demo page broadly equivalent to your competitors: https://brm.io/matter-js/demo/#car


No, I was planning to add that but got busy. There is an existing demo page (https://kinetics.vercel.app/docs/demo), but I agree in the fact that it's more bland than MatterJS demo pages. When I have more time i'll work on both


Why bench mark on a modern dev environment?

If you want to prove something is efficient, pick a 5 year old low end spec.


i've tried on things like replit (i dont have access to old specs), but the mspt was too inconsistent (it varied between 0.7 and 6mspt for 1k circles)




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: