lua-users home
lua-l archive

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

I'm compiling a list of code golfs that look innocent at first but
have a peculiar behavior / explanation.

So far I have these:

a - Table rehashing fun [1]
local t = {}
-- t.slow = true
for j = 1, 1e6 do t[j], t[-j] = 0, nil end

b - Finalizers of hell (mitigated in 5.4)
for i = 1, 1e8 do
   local o = setmetatable({}, {
      __gc = function () end
   -- grow the memory faster
   table.insert(o, {("foo"):rep(1024)})
   table.insert(o, {("bar"):rep(1024)})
   table.insert(o, {("baz"):rep(1024)})
   table.insert(o, {("fubar"):rep(1024)})

c - Find [2]
string.find(string.rep("a", 50), string.rep("a?", 50)..string.rep("a", 50))

For 'b' it's particularly interesting to me since I came across this
issue in production. At the time the mitigation was to tweak the
settings of the GC. In 5.4, the new GC seems to control the
resurrection of the objects much better and the issue seems to have

Please share if you have more scripts like these!