lua-users home
lua-l archive

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


> One thing I have noticed is that the Lua compiler (in both 4 and 5)  
> produces inefficient code.  It has redundant opcodes, unnecessary  
> variable copying and other things.  I'm curious if anyone has attempted  
> to add optimization to the process or if they think it would be useless?

Usually we use redundant opcodes exactly for optimizations: it is
cheaper to execute a single opcode that does the work of two than to
execute two simpler opcodes. (The cost of decoding each opcode is high
in an interpreter.) If there are other redundant opcodes, please let
us know.

The compiler does several on-the-fly optimizations, such as combining
jumps, threaded code for conditionals, direct access to locals and
constants. Because we try to keep the compiler itself small, it does not
optimize some things that can be optimized "by hand" (mainly dead code
elimination and constant folding).

Also, due to metamethods, there are several apparent optimizations
related to redundant computation that cannot be done in a naive way
(e.g., reuse of global and table values).  This also reduces the
value of common subexpression detection. (There are no hidden common
subexpressions that can be eliminated; explicit common subexpressions
can be optimized by the programmer, using local variables.)

Of course we would love to see any further optimization.

-- Roberto