[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: What's up with token filters (Re: New operators?)
- From: Rici Lake <lua@...>
- Date: Sun, 15 Apr 2007 12:37:19 -0500
Asko Kauppi wrote:
Can you give practical examples about cases, where Lua code could be
optimized?
The most important optimization is constant folding and dead-code
elimination.
Lua currently does constant folding, but only for
literal numeric constants (and not for constant comparisons in
if statements).
However, a two-pass compiler could identify locals which are
constant, and propagate this information into the constant
folding stage. That can produce significant speedups.
Another useful optimization would be function call inlining.
If the compiler can prove that a particular closure is
constant, then it can inline the function call, which produces
a dramatic speedup.
I tend to think that compiler optimizations are way more important in
C(++) than in something as high level as Lua. Or, put another way, if
one does sloppy (slow) Lua coding, the compiler wouldn't be smart enough
to "do it right" on your behalf, either.
I.e. replacing a number of a= a..b with table.concat() is way outside of
the optimization scope, right?
That could be done, although it's probably better to write the code
correctly in the first place. :) However, it would theoretically be
possible to handle this in an optimization step:
local a = "prefix"
if some_condition() then
a = a .. " middle"
else
a = a .. " other middle"
end
a = a .. " suffix"
It would be tricky and I don't know that that occurs often to warrant
it. Also, you could just write:
local a = "prefix"
.. some_condition() and " middle" or " other middle"
.. " suffix"
-asko
- References:
- Re: What's up with token filters (Re: New operators?), Robert Raschke
- Re: What's up with token filters (Re: New operators?), Roberto Ierusalimschy
- Re: What's up with token filters (Re: New operators?), Asko Kauppi
- Re: What's up with token filters (Re: New operators?), Luiz Henrique de Figueiredo
- Re: What's up with token filters (Re: New operators?), Fabien
- Re: What's up with token filters (Re: New operators?), Luiz Henrique de Figueiredo
- Re: What's up with token filters (Re: New operators?), Fabien
- Re: What's up with token filters (Re: New operators?), David Given
- Re: What's up with token filters (Re: New operators?), Rici Lake
- Re: What's up with token filters (Re: New operators?), Thomas Lauer
- Re: What's up with token filters (Re: New operators?), Fabien
- Re: What's up with token filters (Re: New operators?), Asko Kauppi