lua-users home
lua-l archive

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

T T wrote:
> [...] and added a big loop at the end, so it runs for a bit.

You're passing a new closure every time -- don't do that. The
compiler specializes to each one of them and bad things happen.

Write that stuff as:

  local function f(x,y)
    return x+y

  for i=1,1e5 do
    ode_dormandprince(f, 0, 1, 1.24, 1e-5, 1, 0.01, 1000)
  print(ode_dormandprince (f, 0, 1, 1.24, 1e-5, 1, 0.01, 1000))

This improves the runtime by an order of magnitude!

Also, the variant with the inline constants is 10% faster and the
generated machine code is about 40% less (2.8K vs. 4.6K on x64).
The effects on performance are less pronounced with FP constants
than with integer constants. I think this matches my prediction
quite well.

> Is code
> templating/specialization/manual unrolling the only way to address
> that in luajit?  Wouldn't it be possible to do something like in the
> example I posted earlier?

There are three different issues:

1. Actual constness of variables that is undetected: needs
   global bytecode analysis. Tricky.

2. Specializing to the actual value of a variable (pseudo-const):
   needs manually inserted directives; variable may lose this
   property if stored/reloaded.

3. Different loop unrolling heuristics: probably needs manually
   inserted directives, too.

Not that simple -- send a patch. :-)