JSKitty / rusty-sandbox

A lightweight sandbox sim written in Rust.
https://stakecubecoin.net/wasm-sandbox/
MIT License
27 stars 0 forks source link

Engine loop scales worse than expected #2

Open JSKitty opened 2 years ago

JSKitty commented 2 years ago

The engine loop (consisting of both Physics and Rendering) is a fair bit slower than I'd expect with the hardware it runs on, often fully maxing out a CPU core with a decent simulation; I suspect there's a lot of optimisations that could be done to help with this, such as better re-sim protection (perhaps only track 'changed state' particles rather than ALL rendered particles?).

We could also potentially implement a system to 'deactivate' buried particles, since if a particle is surrounded below (y + 1) or either side (x +/-) then it cannot possibly move, yet is still included within full physics computation.

And lastly, which is most effective but highly challenging; we could potentially think about multi-threading the engine, but due to it's high reliance on a singular state (how would we be able to simulate two particles at once on two separate threads without a 'desync' in physics determinism?) this may be fairly hard to do.

Live Task List:

JSKitty commented 2 years ago

I'm currently working on this as I speak (re-sim protection optimisation) and thinking of other scaling solutions, but posting this both as a reminder to myself and to let anyone else contribute if desired. :heart:

JSKitty commented 2 years ago

:heavy_check_mark: Re-sim protection optimised!

It was a ridiculously simple improvement which I somehow glanced over - but this has introduced a huge speed-up for the engine in terms of scaling compared to previous levels, yay!