lua-users home
lua-l archive

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

2017-11-24 2:40 GMT-03:00 Tim Hill <>:
> On Nov 23, 2017, at 4:45 AM, Rodrigo Azevedo <> wrote:
> This message is an update about a problem from last year [1] on the performance of the following simple script
> -- collectgarbage("generational")
> N = 2.0e7
> C = {}
> for i=1,N do C[i] = i end
> print(string.format("%.1f",collectgarbage("count")))
> for i=1,10*N do
>     local a = {1,2,3,4}
> end
> print(string.format("%.1f",collectgarbage("count")))
> motivated by the recent statement of Roberto [2] about the "generational" GC of Lua 5.4.
> Results for the script above:
> The "generational" GC from github [3] perform 40% faster than the standard GC.
> Someone versed in GC magics could discuss about the changes made from 5.2 to github version of GC?

I’m confused by this. First, you say that gtihub is 40% faster, but quote no times?

because absolute times are device dependent.
Second, what are your expectations of the GC in Lua? Pretty much all you have done is noticed that the GC has not run during the second “for” loop. So what? Why did you expect it to?


short answer: if I have less than  892302.1 kbytes (lua 5.2/5.3) then that very simple script doesn't finish correctly. Is this really what you expect it to? (I don't)

long answer:

1) first 'for' means: a lot of work for GC manage (dozens Gbytes), consuming almost all we have of free memory.
2) second 'for' means: perform a lot of complex tasks for many hours/days that also create a lot of small (~ Kbytes) GCed temporary objects at a high rate.
3) go to the short answer.

Yes, that is a "toy model" but I also observed the same trends testing with some 'real' (long answer) programs, so that is a valid model.

Observe the attached files for an updated teste2.lua program and also the resulting graph showing the memory usage for lua-5.2.4 generational GC, lua-5.3.4 and github codes.  What did you expect it to?

Many thanks!
Rodrigo Azevedo Moreira da Silva

Attachment: dados.pdf
Description: Adobe PDF document

N = 1.0e4
for A = 1,100,25 do
	C = {}
	for i=1,A*N do C[i] = i end
	local mem1 = collectgarbage("count")
	for B = 1,100 do
		for i=1,B*N*10 do local a = {1,2,3,4} end
		local mem2 = collectgarbage("count")
		print(string.format("%d %d %.1f %.1f",A,B,mem1,mem2))