lua-users home
lua-l archive

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


Curt Carpenter wrote:
> And then there's the perf issue I keep coming back to. Lua
> could be much more performant by keeping a count of elements without any
> extra tag method lookups, function calls, and more table lookups. Maybe
> I'm in the minority, but performance is a very critical facet of the
> language for me. It seems that anything which is broadly applicable and
> useful, and can be done in a generic way internally in Lua much faster
> than you can on top of Lua is a good thing.
> 
> Curt

Yes, but the performance issue cuts both ways. The most simple 
way to keep the count in Lua internally would be to 
add an internal "element_count" variable to each table. 
However, in that case, for each addition or deletion of an element 
to th table, you need to update this internal variable. This
does not sound like much, but what if you have a data table of 
thousands of elements?  

By not keeping track of the amount of elements in a table
internally, you gain some performance whilst adding and deleting 
elements. The price to pay for that is that you will need to perform 
a full table walk to count the amount of elements. The question is, 
"What will be done most frequently?" Adding and removing
table elements, or counting the amount of table elements?

I am inclined to think that table element addition/removal is much
more common. I have no evidence of this, however, so it is merely
my gut feeling. If anyone has any numbers about this, I would be 
interested.

Performance is always a matter of sacrifices. 
You should alays beware not to make a big sacrifice 
for a small gain in speed.


-- 
"No one knows true heroes, for they speak not of their greatness." -- 
Daniel Remar.
Björn De Meyer 
bjorn.demeyer@pandora.be