[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Optimizing off-line Lua compiler
- From: Pavel Antokolsky aka Zigmar <zigmar@...>
- Date: Wed, 27 Apr 2005 14:03:00 +0200
> Sure, luac could do optimizations. In Lua 4.0 and previous versions, it
> did. However, bytecode editing wasn't pretty (though it was a little fun).
> The current internal compiler does several optimizations, but aims only for
> the easy or frequent cases. The trade-off seems good.
It definitely good, lua performance is superb. Just wondering if it
possible to boost performance even more.
> If you can identify patterns in the bytecode that can be optimized, then
> they can probably be added to the internal compiler. Please let us know if
> you find any such patterns.
Unfortunately, my knowledge of compilers is only superficial and I
still lack appropriate skills for such task.
> However, there's a limit to what such peephole
> optimizations can do. Once you reach this limit, the only way to optimize
> code is to do global analysis and this cannot be really done if you only
> have the source code. So, you'd need a different parser and code generator
> for luac, something that we probably do not want to maintain, to ensure
What I actually meant is optimization on global level, because, as you
said, there is a limit of how much you can do at bytecode level.
Having another parser is maintenance overhead, but actually effort
maybe not-so-big - because offine compiler is much less sensible to
size and speed, third party parser can be used in it.
But maybe some optimisation can still be done in bytecode level. For
example, it looks like it possible to locate and compute constant
expressions, from the bytecode. It probably will not benefit much
run-time compiler, because time saved computing such expressions in
run-time, will be spent during compiler time. However, in offile
compiler it can reduce size of the code and increase speed of
> Finally, there's the question of why do this. Isn't Lua fast already?
Yes it is. But we strive for more, don't we? ;)
> What kind of Lua code would benefit from additional bytecode optimization?
I think every kind of code that targeted for systems where code size
(embedded) and run-time performance (RT) is critical.
For more specific example, the code with a lots of math can benefit
from the constant expressions optimisations, mentioned above.