lua-users home
lua-l archive

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


> No, I don't think these will ever be included in the core 
> code generator to avoid bloat. But that doesn't mean that 
> they cannot be done in luac eventually.

 That's fairly reasonable.  Most people looking for the best performance use
luac to precompile their scripts anyway.  You could even ship luac with your
application if you need optimal performance from user created scripts.
Still it should be made easy to optionally link in an enhanced optimizer
with the lua core.

> In general, the core code generator focuses on things that 
> programmers cannot optimize on their own. Constant folding 
> and common expression eliminations are easy to handle using 
> locals (which are very efficient in Lua) and so are left to 
> programmers.

 But I don't think its a good reason to not add these optimizations to luac.
First not everyone using Lua is that experienced of a programmer...
especially for the game developers out there.  At times you have designers,
map makers, or even artists writing some level of Lua code.  Even if the
optimization work is then passed off to a programmer it would be a waste of
man hours and it doesn't always yield the most readable of code.

> But now this is easier to do with long 
> comments (--[[...]]) and carries no cost.

 The sad thing is I avoid long comments because I forget the syntax when I
need it.  The editor I use has an option to auto-comment out stuff with --
and I use that instead.

  Tom


> -----Original Message-----
> From: lua-bounces@bazar2.conectiva.com.br 
> [mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of 
> Luiz Henrique de Figueiredo
> Sent: Thursday, June 17, 2004 8:01 PM
> To: lua@bazar2.conectiva.com.br
> Subject: RE: Optimizations during compilation
> 
> >> No, the code generator does not do constant folding nor common 
> >> expression eliminations. It works hard on other optimizations 
> >> instead.
> >
> > Any plans to implement those then?
> 
> No, I don't think these will ever be included in the core 
> code generator to avoid bloat. But that doesn't mean that 
> they cannot be done in luac eventually. (luac has in the past 
> done some optimizations, specially identification of 
> duplicate constants, but this is now done in the core.)
> 
> >And while we're on the subject, what are some of the other 
> optimizations?
> 
> Roberto will know this better than I do, but the core code 
> generator does jump optimization, that is, try avoids jumps 
> to jumps, for instance. It also does try to identify some 
> constant expression in conditionals. For instance, infinite 
> loops generate code that does not evaluate the condition:
> 
>  [lua:/tmp/L/bin] cat i
>  while true do
>   print(a)
>  end
>  [lua:/tmp/L/bin] luac -l i
> 
>  main <i:0> (6 instructions, 24 bytes at 0x805b678)  0 
> params, 2 stacks, 0 upvalues, 0 locals, 2 constants, 0 functions
> 	 1       [1]     JMP             0 3     ; to 5
> 	 2       [2]     GETGLOBAL       0 0     ; print
> 	 3       [2]     GETGLOBAL       1 1     ; a
> 	 4       [2]     CALL            0 2 1
> 	 5       [1]     JMP             0 -4    ; to 2
> 	 6       [3]     RETURN          0 1 0
> 
> Note the unconditional JMP at line 5.
> 
> In general, the core code generator focuses on things that 
> programmers cannot optimize on their own. Constant folding 
> and common expression eliminations are easy to handle using 
> locals (which are very efficient in Lua) and so are left to 
> programmers.
> 
> The one thing that core code generator does not currently do 
> and which would be nice to help programmers is dead code 
> elimination. Before the introduction of long comments (and 
> after the removal of the preprocessor), the only way to 
> comment code out was by using things like "if nil do ... end" 
> or by creating strings that were never again used. But now 
> this is easier to do with long comments (--[[...]]) and 
> carries no cost.
> --lhf
> 
>