[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: newproxy, bug
- From: Mike Pall <mikelu-1101@...>
- Date: Tue, 11 Jan 2011 00:32:19 +0100
Geoff Leyland wrote:
> If, that is, there was any advantage of newproxy over a proxy
> table. Anyone know if there is one?
Userdata proxies are faster (*) and they can't be messed up by
accident with rawset() or table.insert(). And of course they are
the best choice for real sandboxing.
Also newproxy() is currently the only way to trigger a callback
(via __gc) before the Lua state closes. IMHO newproxy() is quite
useful -- I certainly won't drop it from my codebase.
(*) In particular since Lua has a performance problem with empty
or sparsely populated proxy tables: each write attempt tries to
lookup the key and create a hash slot for it in the proxy table
(this happens *before* even looking for __newindex). But those
hash slots never get a value, so the keys constantly kick each
other out. Depending on the usage pattern, this may lead to lots
of costly branch prediction misses.