lua-users home
lua-l archive

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


On Thu, May 6, 2010 at 12:15 AM, Javier Guerra Giraldez
<javier@guerrag.com> wrote:
> On Wed, May 5, 2010 at 9:21 PM, Luiz Henrique de Figueiredo
> <lhf@tecgraf.puc-rio.br> wrote:
>>> Each of the input lua scripts have the same 5 or 6 strings again and
>>> again, so I was thinking that if string pooling happens, perhaps that
>>> would reduce the size.
>>
>> The Lua compiler already optimizes all constants used in a function and
>> so only one copy of each string exists per function. However, different
>> functions, even if defined in the same chunk, do not share constants
>> (strings, in particular).
>
> no?  i thought each string was unique lua_State-wide

Strings are interned, yes. Lhf was referring to function's needing to
be able to construct their constants (strings in this case) upon
loading. Said differently, the parser doesn't care that another
function defined in the same chunk has the same constant (string), it
remakes the constant in the new function's prototype. However, when
all of the functions are loaded, the loaded constant strings will all
be the same.

So the point he was making is that if you have identical huge strings
defined in multiple functions then your precompiled byte code will be
unnecessary large (as a result of the above). I think you may find it
better to just have your program A save the compressed source code for
each chunk rather than precompile it. In past discussions on this
list, this has been the suggested route.

-- 
- Patrick Donnelly