lua-users home
lua-l archive

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


On Sun, Feb 13, 2011 at 07:37, Mike Pall <mikelu-1102@mike.de> wrote:
> Well, that's the main problem. LuaJIT is not tuned to deal with
> tons of loops that run only 2 iterations. It unrolls them, but
> there's a limit to that and this hits here.
>
> In C++ one would use templates for that purpose. This instantiates
> a copy of the whole code for a specific number of dimensons.
> That's not as wasteful as it sounds, since you probably only ever
> use a finite set of dimensions, e.g. dim=2 and dim=3
>
> In Lua we can do the same: specialize the Lua code at runtime for
> the number of dimensions, memoize the code in a table and dispatch
> based on the dimension. I.e. string.format + loadstring +
> memoization table.
>

It would be great if this specialize/memoize/dispatch optimization for
small number of dimensions could make it into LuaJIT-2.0 release.

As my Physics professor used to say -- dimensionality can be
classified in "1,2,3,4 and many". Covering for 2,3,4 via
specializations would greatly help efforts of efficiently implementing
numerical algorithms in Lua.

--Leo--