lua-users home
lua-l archive

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


Asko Kauppi wrote:


Couldn't a new bytecode be introduced (by Lua authors) that would take less space than current ones. This solution would be totally transparent to Lua end users, imho.

-ak

I'm not sure I understand what Roberto says in his post but the bytecode itself (that is the opcodes) is not the problem. The problem lies in the fact that Lua understands only the word 'number', not 'float', 'integer', 'short' etc. I generally consider this a wise decision but it does have drawbacks as in this case. To save space lua would have to decide per-number wether this number can be encoded in fewer bits (say check wether it is an integer or a real number and how much precision is required) and store it accordingly together with some sort of tag saying how this number should be interpreted. Not very pretty I know although it could be implemented completely transparently to the user. If the only objective is to save disk space then this 'number compression' could be used only in bytecode stored in files. Once the file is read into memory the numbers can be decoded and casted to lua_Number and the user will never know the difference. The memory image of the script will still be big but the disk file will be smaller. Storing the numbers encoded in memory as well would reduce memory space overhead but would introduce a lot of decoding and casting time overhead on anything number related. Therefore this solution besides introducing quite a bit of complexity would propably be completely unacceptable from a performance point of view. Even worse hacks could be done by trying to optimize only 'big' arrays (tables) of numbers instead of single numbers but they would propably lead nowhere as well. Still Lua would benefit from a solution to this problem. It would be really cool if most apps would stop using special-purpose binary or ascii data files, each with its own syntax and therefore needing its own parser and using standard scripting language files (preferanly lua :)) to do the job.

Dimitris