lua-users home
lua-l archive

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


This message is an update about the performance of the following code below, designed to be a minimum benchmark of some Lua-ish features that also performs an ordinary real-world convolution operation.
 
################# BEGIN  #################
-- teste_gc.lua
--collectgarbage("incremental")
--collectgarbage("generational")
N = 2.0e7

C = {}
for i=1,N do C[i] = i end

local max,min = math.max, math.min
local conv = function(u,v)
  local m,n = #u,#v
  local w = {}
  for k=1,m+n-1,1 do
    local sum = 0.0
    for j = max(1,k+1-n),min(k,m) do sum = sum + u[j]*v[k-j+1] end
    w[k] = sum
  end
  return table.unpack(w)
end

print(string.format("%.1f",collectgarbage("count")))
for i=1,2*N do
    local a,b = {1,2,3,4},{5,6}
    local res = {conv(a,b)}
end
print(string.format("%.1f",collectgarbage("count")))

################# END #################

Methodology:

Default lua5.2 and lua5.3 from Ubuntu.  Lua 5.4 (work1) compiled *without* -D_LUA53COMPAT and -D_NILINTABLE.

Default parameters of gc. I'm not trying to optimize anything, only checking the default options of each Lua version.

Results:

----------------------

time lua5.2 teste_gc.lua
524315.5
1225547.7 -- NOT GOOD

real    1m33.749s
user    1m33.313s
sys    0m0.412s

------------------------

time lua5.3 teste_gc.lua
524315.5
1225487.5 -- STILL NOT GOOD

real    1m32.680s
user    1m32.051s -- NO CHANGE
sys    0m0.588s

-----------------------

INCREMENTAL GC

time ./lua5.4 teste_gc.lua
524309.6
1028321.7 -- BETTER THAN PREVIOUS, BUT NOT YET GOOD

real    1m13.322s
user    1m13.083s -- THANKFUL SURPRISE
sys    0m0.240s

----------------------

GENERATIONAL GC

time ./lua5.4 teste_gc.lua
524309.6
596331.1 -- VERY GOOD, AWESOME

real    1m9.472s
user    1m9.208s -- ALSO AWESOME
sys    0m0.172s

-----------------------------

Discussion:

The (default) generational garbage collector of lua5.4 performs much better than all previous versions, concerning memory usage AND  time! That's awesome.

Conclusion:

Thank you very much Lua team!

Question: Why the incremental Lua 5.4 performs better (CPU TIME) than Lua 5.2 or 5.3? My guess is the new VM instructions (what are the new ones?), am I right? or some optimization of the incremental gc? anything else?

(I've tried (5.4) luac but it seems to be "not yet ready")

--
Rodrigo Azevedo Moreira da Silva