Use of ephemeron degrades GC performance

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Use of ephemeron degrades GC performance

Renato Maia
Hi list.

Why the following use of a ephemeron table to keep a chain of weakly referenced values degradates the GC performance?

  local weakkeys = setmetatable({}, { __mode = "k" })

  local strong = {}
  for i = 1, 1e5 do
    local value = {}
    weakkeys[value] = strong
    strong = value
  end

These are the times such script takes to execute in my machine in the different versions of Lua with support for ephemerons:

  Lua 5.2.4
  real   0m7.222s
  user   0m7.192s
  sys    0m0.000s

  Lua 5.3.5
  real   0m42.718s
  user   0m42.656s
  sys    0m0.028s

  Lua 5.4.0-alpha
  real   2m26.025s
  user   2m25.892s
  sys    0m0.032s

The following code creates a similar reference structure,

  local weakkeys = setmetatable({}, { __mode = "k" })

  local strong = {}
  for i = 1, 1e5 do
    local value = {strong}
    weakkeys[value] = true
    strong = value
  end

but the GC goes back to its normal performance:

  Lua 5.2.4
  real   0m0.075s
  user   0m0.064s
  sys    0m0.008s

  Lua 5.3.5
  real   0m0.068s
  user   0m0.056s
  sys    0m0.012s

  Lua 5.4.0-alpha
  real   0m0.062s
  user   0m0.056s
  sys    0m0.004s

Any insight is very welcome.
Reply | Threaded
Open this post in threaded view
|

Re: Use of ephemeron degrades GC performance

Roberto Ierusalimschy
> Why the following use of a ephemeron table to keep a chain of weakly
> referenced values degradates the GC performance?
>
>   [...]

See http://www.inf.puc-rio.br/~roberto/docs/ry08-06.pdf (in particular
Section 5).

-- Roberto