lua-users home
lua-l archive

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


I've been playing around with LuaJIT and the performance is quite
good. For most of my applications, I am seeing the running time cut by
30% to 50%! I did notice a few cases where code runs slower with jit
compilation, and in each case it was code which creates a lot of
functions dynamically (to use as iterators). Here's the smallest
example I could come up with, it runs about four times slower with jit
vs stock Lua:

local function count(n)
   return coroutine.wrap(function()
    for i=1,n do coroutine.yield(i) end
  end)
end
local v = {}
for i=1,1e5 do
  for n in count(math.random(1,5)) do v[#v+1]=n end
end

Are ALL functions jit-compiled the very first time they are called?
Would it make any sense to have some higher threshold, as in, after a
function has been called K times, it is jit compiled? Or some other
more clever workaround so that the compiler doesn't spend too much
time compiling and optimizing what are basically throw-away functions?

-Paul