lua-users home
lua-l archive

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


On Sep 10, 2012, at 1:45 PM, Roberto Ierusalimschy wrote:

>> i'm studying lua's implement now, i'm wondering why lua's table need a
>> dummy node, why not just set node to NULL if table's hash part is empty?
>> could someone tell me the reason?
> 
> It avoids an extra test (t->node == NULL) when querying tables.

My instinct is the test itself should be somewhere between cheap and free these days. For non-empty tables there would be an additional predicted-not-taken branch, taking up icache and some vague non-architected resources. For empty tables, a NULL check would avoid the latency of a memory access and the trivial cache pressure of having the dummy plug--er, dummy node sitting around.

This sounds like just the kind of change you'd have to run on four generations each of major CPU architectures to see if it's a win. With my luck, some other change would provoke the optimizer into screwing up the scheduling, or breaking speculative execution etc etc etc. My detailed experience ends at somewhere around the Pentium Pro generation. I have had this message sitting in drafts for weeks because I thought I might go read the assembly code on a couple of architectures and figure out how it actually executed. Nope.

If performance is close, clarity and simplicity wins. The time everyone spent reading this message is probably greater than the potential combined execution time savings on all Lua instances.

Jay