lua-users home
lua-l archive

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


Matt Campbell wrote:
I've noticed that Lua 5.1 bytecode, compiled with the -s option, doesn't compress as well as the equivalent Lua source code. I have a Lua source tree that's about 1.4 MB uncompressed, and when I compress it with 7-Zip using LZMA and solid compression, the archive's file size is 183,262 bytes. But when I compress the equivalent bytecode, that archive's file size is 265,289 bytes. For what it's worth, I'm doing the compile on an x86 machine, so integers are 32-bit, little-endian. Can anyone explain these counter-intuitive results? Thanks in advance.

Not counter-intuitive at all. There's just fewer redundant patterns in binary chunks to do compression at the same ratio as with a text file. Probably you won't get much out of the LZ phase; the bulk of the reduction is probably due to the range coding bit.

You can create a custom format that is aware of certain characteristics of binary chunks (like what some archivers do to improve compression of executables) but IMHO, it's not really worth the effort. Is it really necessary?

Look at a binary chunk in a hex editor. If you can reduce all those zero bytes by writing a custom binary chunk format, you can probably save quite a bit of space with a close to zero performance hit.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia