lune-org/lune

Investigate other async runtime(s)

filiptibell opened this issue · 1 comments

Lune currently uses tokio as its async runtime, and while it is the most popular within the Rust ecosystem, it comes with some caveats:

  1. Tokio is multithreaded and uses a global executor by default - meaning every future needs to be Send + 'static, or sometimes even Send + Sync + 'static
  2. We need to make sure all of our lua-related futures meet these requirements, even though Luau is and will remain completely singlethreaded - this also makes dealing with the 'lua lifetimes in mlua much more complicated
  3. There is a small but not insignificant performance cost to using primitives like Arc and Mutex over non-Sync equivalents like Rc and RefCell
  4. Multithreaded runtimes tend to actually make io-bound performance worse (source)

Of course, using a multithreaded runtime also has benefits:

  • We currently offload some work in the net built-in library to background tasks
  • Spawning blocking tasks such as subprocesses onto background threads is trivial

We should investigate using a different async runtime, such as smol, for a local executor that does not impose Send + Sync + 'static requirements on our futures, and potentially spawning more localized runtimes for offloading async background tasks such as in our net.serve implementation. Threadpools and blocking can be used for the rest.

Investigation has been completed, and we now have a more flexible scheduler/runtime implementation here:
https://github.com/lune-org/mlua-luau-runtime
Integrating this new runtime is currently underway on this branch:
https://github.com/lune-org/lune/tree/smol