LuaSrcDiet工具介绍,lua源码处理软件

Food

  • Diet (nutrition), the sum of the food consumed by an organism or group
  • Dieting, the deliberate selection of food to control body weight or nutrient intake
    • Diet food, foods that aid in creating a diet for weight loss

https://en.wikipedia.org/wiki/Diet

  • 节食;进行规定饮食
  • n.日常饮食;日常食物;规定饮食(为健康或减肥等目的);规定饮食的时期
  • Web食性;食谱;膳食

https://www.bing.com/dict/search?q=diet&FORM=BDVSP2&qpvt=diet

Diet 结合工具的使用, 应该是节食的含义, 即使用规定的饮食,达到减肥的目的。

luaSrcDiet

知道了英文的意思, 这里luasrcdiet == lua source code diet, 即 对lua源代码进行瘦身。

http://luasrcdiet.luaforge.net/

LuaSrcDiet reduces the size of Lua 5.1.x source files by aggressively removing all unnecessary whitespace and comments, optimizing constant tokens, and renaming local variables to shorter names.

LuaSrcDiet squeezes its own (heavily commented) sources from 121KB down to 28KB. Further compression (bzip2 or lzma) brings the size down to under 10KB, representing a 12X reduction in size.

Sample Output

The following is the result of processing llex.lua from LuaSrcDiet 0.11.0 using various optimization options:

LuaSrcDiet OptionSize (bytes)Link to Sample File
Original12,421llex.lua.txt
Empty lines only12,395llex_emptylines.lua.txt
Whitespace only9,372llex_whitespace.lua.txt
Local rename only11,794llex_locals.lua.txt
--basic (token optimizations only)3,835llex_basic.lua.txt
Program default3,208llex_default.lua.txt
--maximum3,130llex_maximum.lua.txt

功能

LuaSrcDiet features include the following:

  • Predefined default, --basic (token-only) and --maximum settings.
  • Avoid deleting a block comment with a certain message with --keep; this is for copyright or license texts.
  • Special handling for #! (shbang) lines and in functions, "self" implicit parameters.
  • Dumping of raw information: lexer tokens and local variable name tracking information
  • Plugin interface (experimental!) with HTML and SLOC plugins.
  • HTML plugin: outputs files that highlights globals and locals (useful for eliminating globals), sample: html_sample.html.

    -----

    这个挺好@!!!!!

  • SLOC plugin: counts significant lines of Lua code, like SLOCCount.

List of optimizations:

    • Line endings are always normalized to LF, except those embedded in comments or strings.
    • --opt-comments: Removal of comments and comment blocks.
    • --opt-whitespace: Removal of whitespace, excluding end-of-line characters.
    • --opt-emptylines: Removal of empty lines.
    • --opt-eols: Removal of unnecessary end-of-line characters.
    • --opt-strings: Rewrite strings and long strings. Sample: Before and After
    • --opt-numbers: Rewrite numbers. Sample: Before and After
    • --opt-locals: Rename local variable names. Does not rename field or method names.
    • --opt-entropy: Tries to improve symbol entropy when renaming locals by calculating actual letter frequencies.

与其他工具对比

File sizes of LuaSrcDiet 0.11.0 main files in various forms:

Source FileOriginal Size

(bytes)

luac normal

(bytes)

luac stripped

(bytes)

LuaSrcDiet

--basic (bytes)

LuaSrcDiet

--maximum (bytes)

LuaSrcDiet.lua21,96120,95211,00011,0058,159
llex.lua12,4218,6134,2473,8353,130
lparser.lua41,75727,21512,50611,7557,666
optlex.lua31,00916,9928,0219,1296,858
optparser.lua16,5119,0213,5205,0872,999
Total123,65982,79339,29440,81128,812
Null

loop

Stripped

binary chunk

Original

Sources

Squeezed

Sources

Total Size(bytes)039,294123,64028,793
Iterations312,1559,68013061,592
Duration(sec)10101010
Time/iteration(msec)0.0321.0337.6576.281
Time/iteration, adjusted for null(msec)-1.0017.6256.249
Load rate(MB/sec)-37.4415.464.39
Load time per byte(ns)-25.561.7217.0
Load time per token(ns)--682559
Source time vs binary chunk time ratio-1.007.626.24
Binary chunk rate vs. source rate ratio-1.002.428.53

The LuaSrcDiet 0.11.0 files (original, squeezed with --maximum and stripped binary chunks versions) are loaded into memory first before a loop runs to repeatedly load the script files for 10 seconds. A null loop is also performed (processing empty strings) and the time taken per null iteration is subtracted as a form of null adjustment. Then, various performance parameters are calculated. Note that LuaSrcDiet.lua was slightly modified (#! line removed) to let the loadstring function run. The results below were obtained with a Lua 5.1.3 executable compiled using "make generic" on Cygwin/Windows XP SP2 on a Sempron 3000+ (1.8GHz). The LuaSrcDiet 0.11.0 source files have 11,180 'real' tokens in total.

Null

loop

Stripped

binary chunk

Original

Sources

Squeezed

Sources

Total Size(bytes)039,294123,64028,793
Iterations312,1559,68013061,592
Duration(sec)10101010
Time/iteration(msec)0.0321.0337.6576.281
Time/iteration, adjusted for null(msec)-1.0017.6256.249
Load rate(MB/sec)-37.4415.464.39
Load time per byte(ns)-25.561.7217.0
Load time per token(ns)--682559
Source time vs binary chunk time ratio-1.007.626.24
Binary chunk rate vs. source rate ratio-1.002.428.53

The above shows that stripped binary chunks is still, in many ways, the highest-performance form of fixed Lua scripts. On a very average machine, scripts load at over 37MB/sec (in memory). This is very comparable to the burst speeds of common desktop hard disks of 2008. If instant response is paramount, stripped binary chunks has little competition.