lua-users home
lua-l archive

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


Hi all,

LuaSrcDiet 0.11.0 release - local var name optimization
-------------------------------------------------------
http://luaforge.net/projects/luasrcdiet/

This is a brief announcement for a major milestone for LuaSrcDiet,
which is a utility for reducing the size of Lua source code by
removing unnecessary characters.

Version 0.11.0 is the first release with local variable name
optimization for Lua 5.1.x source code. Local variable names are
renamed into the shortest possible names. In addition, variable names
are reused whenever possible, reducing the number of unique variable
names. Several hundred local variable name tokens can be reduced into
53 or less unique names, which allows all locals to be
single-character in length.

The local variable name optimizer uses a full parser of Lua 5.1 source
code, thus it can rename all local variables, including function
parameters. It should handle the implicit "self" parameter gracefully.
The optimizer needs more testing, but is already able to optimize
LuaSrcDiet itself and the squeezed second-generation sources generates
the same output.

For example, llex.lua in LuaSrcDiet is 12421 bytes originally. Basic
(token-based only) optimization gets it down to 3835 bytes. Maximum
optimization (with local variable name renaming) gets it down to 3130
bytes. Note that it's not obfuscation, as the token stream still looks
identical to Lua. In an actual application, the source code can be
further compressed, saving more space.

String and number token optimizations are also performed, apart from
the usual whitespace, line ending and comment removal. Numbers can
switch between different formats. Strings can be simplified and can
switch delimiters between " or ' characters.

Squeezed samples are available in the file release. Most options can
also be enabled or disabled separately, for maximum flexibility. If
you need to keep a copyright message in the optimized output, the
--keep option can keep block comments that contain a certain string.

Near future plans involves writing test cases and setting up a test
harness. LuaSrcDiet uses the same license as Lua.

Many thanks to LuaForge for hosting all this. :-) [Sorry if this
e-mail appears awful; gmail smtp isn't working well.]

--
Cheers,
keinhong
KL, MY