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:
- Tokio is multithreaded and uses a global executor by default - meaning every future needs to be
Send + 'static
, or sometimes evenSend + Sync + 'static
- 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 inmlua
much more complicated - There is a small but not insignificant performance cost to using primitives like
Arc
andMutex
over non-Sync
equivalents likeRc
andRefCell
- 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