We love coroutines! Coroutines allow us to make lines of code run separately from others, and this is great when you want to wait for something and still having another bit of your script run. But just how many different coroutines can a Roblox server run at the same time? I know that for clients it’s somewhere near 4-8 threads, but Roblox servers should be way more powerful, right?
tl;dr: How many coroutines have to run at the same time for them to stop running in separate threads on server scripts?
A coroutine is similar to a thread (in the sense of multithreading): a line of execution, with its own stack, its own local variables, and its own instruction pointer; but sharing global variables and mostly anything else with other coroutines. The main difference between threads and coroutines is that, conceptually (or literally, in a multiprocessor machine), a program with threads runs several threads concurrently. Coroutines, on the other hand, are collaborative: A program with coroutines is, at any given time, running only one of its coroutines and this running coroutine only suspends its execution when it explicitly requests to be suspended.
In other words, a script can make as many coroutines as memory allows. They don’t run in parallel – during execution, the VM just jumps to a new one whenever the current coroutine calls coroutine.yield() (e.g. via wait() or one of the -Async() methods).
All of these threads can run concurrently with (from my brief testing) no performance draw backs and relatively low memory usage. You will realistically never run into a coroutine limit in your coding, and if you do that’d be an issue of drastic memory drawbacks for your games other assets.
Roblox might release real multithreading soon (it’s on the roadmap) , it would be good to know how much threads a server will have once this is released.