lua-users home
lua-l archive

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


On Sun, Feb 13, 2011 at 7:22 PM, Francesco Abbate
<francesco.bbt@gmail.com> wrote:
> thank you very much for your answer. Now everything is much more clear
> for me. I've got the feeling that something in the code was preventing
> LuaJIT from performing the needed optimizations and the results with
> FFI was especially surprising to me but now everything is clear.

It would be a most excellent idea if these discussions could be
summarized as a lua-users wiki page.

The thing is, we have been spoiled by optimizing compilers for the
last 20 years, and so the advice about hand-optimization has basically
been "leave it to the compiler".  But LuaJIT is still young, and there
are things that need to be explicitly handled. But it is comforting to
see that the code that works best is plain, simple Lua that avoids
thrashing the GC.

On the subject of templates, I think the Rici Lake preprocessor I
mentioned in another thread would make an excellent Lua 'template'
engine.  You want to unroll a loop in a template, that's
straightforward:

smooth3 = compile ([[
return function (y,f1,f2,n)
   for i = 1,n do
      # for d = 1,nk do
      y$(d)[i] = f1*y$(d)[i] + f2*y$(d)[i-1]
     # end
  end
end
]],{nk = 3})

Naturally, other notations are possible, and heaven knows there are
enough Lua template engines.

steve d.