lua-users home
lua-l archive

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

2008/10/31 Max van Rooij (van Rooij Electronics Design & Software
Engineering) <>:
> I've already established that the GC is the culprit for the delays. I
> just need to run the GC at every coroutine.yield, and gone are my
> delays. I never experienced any other "bad" behaviour such as crashes,
> wrong answers or whatever. It was just the delays. The delays are caused
> by the GC.
> I only want to know, _why_ is the Lua memory required at run time for a
> thread growing? And it _appears_ to be growing proportional to the size
> of the cel variable. It doesn't matter what _type_ of data the cel
> variable holds. It also doesn't matter wheter or not this variable is
> actually used in the thread or in the program at all.
> My theory is, that with every thread create, some space is allocated for
> the thread (which is natural), but also some additional space for the
> "global" variables accasible for that thread...The space required for a
> thread should be constant, but it isn't. It's directly proportional to
> the size of the variable cel. This is weird behaviour.

There is no reason for such a behaviour. New threads only point to
their parent's global table. No deep copy of data ever happen

> Maybe a few hints on where to look in the Lua sources?

I have no knowledge of Lua internals, but what I know is that there
are many ways to 'implement' your problem from the bits of code that
you didn't supply. IMHO you should look there first (or allow us to
look there) before looking at Lua internals.

However since I've got time to waste, I modified the code you gave us
to make it compile.

- Funcs-n.lua is the init Lua code with numbers in cel

- Funcs-u.lua is the init Lua code with userdata in cel

- ApplThread.lua is the loop Lua code

- Lua.c is the main C program. It takes the init script name as first
parameter, and the number of coroutine created as second parameter.

And a few runs here:
> time Lua Funcs-n.lua 1024
> time Lua Funcs-u.lua 1024
> time Lua Funcs-n.lua 65536
> time Lua Funcs-u.lua 65536
> time Lua Funcs-n.lua 262144
> time Lua Funcs-u.lua 262144

There is a small increase when using userdata (5-9%). This is probably
due to the way the memory allocator works (ie. doubling already used
memory when more is necessary) and the fact that more memory is
allocated at startup when building the userdata table (and thus
doubling that is more costly).

On the other hand this is nothing compared to the 10 000% you
mentionned (20msec agains 1700-2500msec). So there must be something
different in your setup.