coroutines once more...
lukas.stadler at jku.at
Tue Dec 1 09:11:22 PST 2009
I would be very interested to hear what the expectations for a coroutine
implementations for Java are. I am asking because I am facing some
initial design decisions on my way.
There is a quite simple tradeoff between memory/address space usage and
* Using "traditional" implementations context switches are very cheap
(constant time), but at least 12-16 kb of memory and 16-32 kb of address
space is used per coroutine. This can exhaust 32-bit address space with
~50000 coroutines. And in order to do something useful we might need
larger stack sizes, which lowers this number even further. A coroutine
might need a larger stack size even though it occupies only a fraction
of it while it is suspended. Creating and removing coroutines is expensive.
* A more space-preserving implementation only keeps the parts of the
coroutine in memory that it actually uses. It will be able to handle
millions of coroutines, but this comes at the cost of a more complex
context switch. Creating and removing coroutines is very cheap this way.
For small coroutine it might be prohibitively expensive to allocate a
real stack, but other applications might benefit from the fast context
switch. Maybe I should aim for a hybrid solution?
More information about the mlvm-dev