[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: RE: Tons of reallocs in Lua - why?
- From: Ivko Stanilov <ivko@...>
- Date: Fri, 22 Dec 2006 15:30:35 +0200
>BTW, you still did not tell us where those reallocs come from (not all
>the allocations, only the reallocs). From a quick search, Lua reallocs
>in three places:
>- the parser (reallocs all kinds of arrays used to represent a function);
>- the stack (deep call chains, or new coroutines);
>- tables (usually new arrays growing);
>Can you find out which of these is calling so many reallocs?
This is easy - the reallocs come from tables growing. We are probably
using Lua a bit carelessly, but we like the intrinsic power of the
language constructs and just use them. In our code, it's a common
practice to create temporary tables and then use "table.insert" to
populate them. We also have a thread manager written in Lua, which
uses tables to store lists of threads (coroutines) sheduled to be
executed, and is a very central part of our system.
I think you could add a mininum table allocation size (or minumum
allocated entries at table creation) macro in 'luaconf.h'. Because
we're not limited by memory constraints, we'd happily set this
value to 8 or 16 if it existed, so we can save time from
reallocations. But I'm not so sure about this, since I guess we could
just optimize our code ;)