lua-users home
lua-l archive

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


On Jun 18, 2014, at 6:50 AM, Thomas Jericke <tjericke@indel.ch> wrote:

> On 06/18/2014 01:34 PM, Paige DePol wrote:
>> On Jun 18, 2014, at 5:55 AM, Thomas Jericke <tjericke@indel.ch> wrote:
>> 
>>> On 06/18/2014 12:50 PM, Paige DePol wrote:
>>>> On Jun 17, 2014, at 9:27 PM, Sean Conner <sean@conman.org> wrote:
>>>> 
>>>>>  Do note that the compiled Lua script may not necessarily be smaller than
>>>>> Lua source code.  Also, I've found that compressed Lua scripts are smaller
>>>>> than compressed compiled Lua scripts (using zlib---it's not a hard library
>>>>> to use and there are Lua wrappers for it).
>>>>> 
>>>>>  -spc
>>>> Do you have an example of a Lua script that results in a larger compiled file vs source file? I am curious to see how that could happen. I would think that having a script compile and be larger would be a fairly uncommon occurrence.
>>>> 
>>>> I can see how compressed source could be smaller than compressed compiled source, though on a restricted system that would just add additional memory and processing overhead for decompression. The idea was to skip parsing altogether and just load binary scripts, leaving the possibility of removing the parser from the library, which is a 35% reduction in the size of the Lua core according to Luiz.
>>>> 
>>>> ~pmd
>>>> 
>>>> 
>>> Actually that is quite easy by just creating a table of numbers:
>>> 
>>> return {1,2,3,4,5,6,7,8,9,0,1,6,3,2,2,2,4,6,7,2,7,8,3}
>>> 
>>> As Lua bytecode stores all numbers as doubles (by default) the source code will be smaller as long as the numbers have less then 8 digits.
>>> --
>>> Thomas
>> LoL, okay you got me there! ;)
>> 
>> Though I was hoping for an example of a real world script that is not just code golf to make a larger compiled file.
>> 
>> ~pmd
>> 
>> 
> I don't think that the example is so far away of the real world. Think of configuration scripts, that essentially only store options.
> --
> Thomas

Okay, again, good point! :)

While compiled binary scripts can be larger than the original source, I still think it would be an uncommon case overall, especially if the binary file was also stripped of debugging information. Now I want to go grab a bunch of random Lua scripts and compile them! ;)

For the situation that originated this discussion, the use of Lua on restricted hardware, I think the use of compiled (and stripped) scripts and the removal of the parser from the Lua core could be beneficial overall.

~pmd