Peculiar scripts

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

Peculiar scripts

Pedro Tammela-2
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)})
end
```

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
disappeared.

Please share if you have more scripts like these!

Pedro

[1] https://marc.info/?l=lua-l&m=160147165306326&w=2
[2] http://lua-users.org/lists/lua-l/2011-02/msg01595.html
Reply | Threaded
Open this post in threaded view
|

Re: Peculiar scripts

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

A good place to store these with comments and discussion is GitHub.