lua-users home
lua-l archive

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

On Sat, 21 Feb 2009, Mark Hamburg wrote:

> You can avoid the error problem by using a userdata and letting the GC collect
> it. That gets expensive relative to malloc/free if you do it every time since
> the GC is necessarily more expensive than the free. We could work around that,
> however, by doing the following:


Chucking together a simple microbenchmark to test userdata overhead, 
I'm seeing a well tuned GC running at ~ 1.6x the speed of explicitly 
doing malloc/free, and even the default tuned GC running at ~ 3.2x.  
It only takes a handful of table lookups or string-intern checks to 
dwarf that overhead.  The take home message for me is that full 
userdatas are the way to go for almost all allocation, especially 
taking into account how much easier they make writing lua-exception 
safe C code.