Running auto-evo in a background thread

I just thought of a way to reduce the lag by a significant amount, especially once auto-evo gets implemented: running the expensive simulations in a background thread. Right now thrive only uses a single thread and that is quite problematic for expensive computations. Currently there are quite a few frame drops when things spawn, and I believe that will only get worse as we add more stuff.

So the solution is multithreading. The issue is that Lua doesn’t support multithreading (and neither does the thrive engine). So the actual solution is creating a separate Lua state or a C++ thread that does expensive computations without accessing any external data (to keep it simle) and sends simple messages to the main thread.

Of course that might have bottleneck issues with the messaging, but if we move big enough, encapsulated things to a background thread it should be fine.


That sounds like a very promising idea. What happens if people don’t have multi-threading on their processors? Will this system be accessible to everyone? (I don’t really know much about how it works).

Multithreading is handled by the operating system by distributing threads to available cores. So it doesn’t matter if there aren’t enough cores for all threads to run simultaneusly; they can share time on a single core. It will get horribly slow if there aren’t enough cores to allow the threads to run their tasks in a timely manner, though. But basically there won’t be any issues. Other than if someone’s computer just doesn’t have enough power to run all parts of the simulation at an acceptable speed, but that issue is also present when doing single threading.

This is probably explained better on Wikipedia

1 Like