Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Multithreading in Lua #102

Open
Tracked by #217
dgavedissian opened this issue Jun 2, 2023 · 2 comments
Open
Tracked by #217

Support Multithreading in Lua #102

dgavedissian opened this issue Jun 2, 2023 · 2 comments
Labels
engine Any PR/Issue affiliated with the engine portion of LTR script Any PR/Issue affiliated with the script portion of LTR

Comments

@dgavedissian
Copy link
Collaborator

Currently, the Lua VM is completely single threaded with some cooperative multitasking support using coroutines. This will still saturate the main thread and limit performance.

Some multithreading frameworks exist (with significant code support on the native side), such as:

I think the rough idea is that we want to have one Lua VM for each thread, and utilise some kind of message passing protocol to communicate between the "threads". That means passing only basic Lua objects like strings/ints/etc that can be serialized/deserialized to bytes, essentially equivalent to a networking protocol but within a single process.

@IllustrisJack
Copy link
Member

Lua problems:

  • Heavy tasks like iterating large tables or running functions that need to do so e.g. system creation will bring the main thread pretty much to a halt. This will make the game almost crash as it depends on the Lua VM to handle everything. Especially system & ship generation freeze the main thread until it's fully done and we can't simply pause / the user can't do anything else in the application while these are happening.
  • Also I can see things like the economy simulation etc being offloaded as these put unnecessary strain on the main thread.

@IllustrisJack
Copy link
Member

Currently a system is generated like this https://github.com/Limit-Theory-Redux/ltheory/blob/main/script/GameObjects/Entities/Test/System.lua

While there are lots of things that can still be optimized in lua (already on it) we will eventually reach a ceiling which needs to be addressed sooner or later.

@IllustrisJack IllustrisJack added engine Any PR/Issue affiliated with the engine portion of LTR script Any PR/Issue affiliated with the script portion of LTR labels Jan 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
engine Any PR/Issue affiliated with the engine portion of LTR script Any PR/Issue affiliated with the script portion of LTR
Projects
None yet
Development

No branches or pull requests

2 participants