Quantcast WoWInterface - View Single Post - Are all addon "open source"?
View Single Post
12-11-13, 07:25 AM   #17
Resike
A Pyroguard Emberseer
AddOn Author - Click to view addons
Join Date: Mar 2010
Posts: 1,289
The Lua compiler translates programs written in the Lua programming language into binary files that can be loaded and executed with lua_dofile in C or with dofile in Lua.
The main advantages of precompiling chunks are: faster loading, protecting source code from user changes, and off-line syntax error detection.

Pre-compiling does not imply faster execution because in Lua chunks are always compiled into bytecodes before being executed. The compiler simply allows those bytecodes to be saved in a file for later execution.

Longer variable names would never have an impact on runtime performance in a compiled language. But in a just-in-time compiled language, it could slowdown program startup and program performance.

For dynamic languages such as Lua or Python or Ruby, the length of a variable name could very well affect runtime performance depending on how variable name lookups are performed. If variable names are hashed and then the hash is used to index a table of values to get the value of the variable, then natrually the more data the hash function has to process, the longer it will take.

When you compile this:

Lua Code:
  1. local x = 1

The compiled file will be this:

Lua Code:
  1. 1b4c 7561 5100 0104 0404 0800 0700 0000
  2. 4078 2e6c 7561 0000 0000 0000 0000 0000
  3. 0002 0202 0000 0001 0000 001e 0080 0001
  4. 0000 0003 0000 0000 0000 f03f 0000 0000
  5. 0200 0000 0100 0000 0100 0000 0100 0000
  6. 0200 0000 7800 0100 0000 0100 0000 0000
  7. 0000

And if you complie this:

Lua Code:
  1. local xxxxxxxxxxxxxxxxxxxxxxx = 1

You will get this:

Lua Code:
  1. 1b4c 7561 5100 0104 0404 0800 0700 0000
  2. 4078 2e6c 7561 0000 0000 0000 0000 0000
  3. 0002 0202 0000 0001 0000 001e 0080 0001
  4. 0000 0003 0000 0000 0000 f03f 0000 0000
  5. 0200 0000 0100 0000 0100 0000 0100 0000
  6. 1800 0000 7878 7878 7878 7878 7878 7878
  7. 7878 7878 7878 7878 7878 7800 0100 0000
  8. 0100 0000 0000 0000

- Used lua 5.1.

Since the variable name is more then 8 charaters the compiler can't transalte that variable name into 1 bytecode, so it will take up more space, and since the code is longer the execution is going to take more time.

You are right about it's might be irrelevant for 100-200 kB codes or i7 12 core processors, but it still a performance improvement, bit faster execution, less memory fragmentation.
  Reply With Quote