lua-users home
lua-l archive

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


I knew about the cache bits but I hadn't thought about the invalidation
issues. I'm now mulling over whether it would make sense to allow some but
not all metatable entries to be inheritable.

Mark

on 6/3/05 4:08 AM, Mike Pall at mikelu-0506@mike.de wrote:

>> Is there a particular reason why metamethod search doesn't obey __index
>> links?
> 
> Performance.
> 
> Metamethods are cached (or rather the non-existence of some of
> them). This is done with a few bits in the table anchor structure
> (of a metatable). A cache bit is set when a metamethod is
> looked up, but not found. The cache is invalidated when the
> metatable is modified.
> 
> This simple scheme no longer works with recursive metamethod
> lookups. It would require an exhaustive search every time.
> While this is not so bad for __index (which is the reason why
> most tables have metatables in the first place), it's pretty
> bad for __mode (needed by the GC on every traversal).