lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jun 15, 2008, at 12:36 PM, Mike Pall wrote:

Graham Wakefield wrote:
Does this mean that using large numbers of coroutines (e.g. hundreds
concurrently, or hundreds of thousands over a program's lifetime) may be
more expensive in luajit 1.x than plain lua?

Yes, unfortunately. At least if you need all of them to be alive
at the same time.

That's too bad... but makes sense.

Try to recycle coroutines instead of creating
and collecting them repeatedly.

I did that in an earlier project... but I wasn't entirely confident that what I was doing was stable.

What I gathered from the list is that a coroutine that errors cannot be recycled, but one that returns with no error can have its stack cleared and be ready to be re-used. I just wondered if there was any more to it that this; should I worry about any changes of environment, metatables etc. that may have had side effects on the lua_State, and which would lead to undefined behavior if recycled?

The minimum amount of memory for a coroutine in LuaJIT 1.x is ~37K
(and much more on Windows due to limitations of Windows Fibers).


And if so, is this also
likely to be the case in the eagerly anticipated luajit 2.0?

No. The minimum amount of memory for a coroutine in LuaJIT 2.x
will be ~450 bytes (thread object plus minimum Lua stack).