[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Fast metamethods for Userdata types
- From: Dibyendu Majumdar <mobile@...>
- Date: Wed, 8 Apr 2015 00:07:05 +0100
On 7 April 2015 at 23:43, Rena <hyperhacker@gmail.com> wrote:
> I suppose you might see some performance gain (at the cost of memory)
> by having an array associated with each userdata, which stores
> pointers to C functions for each metamethod at particular indexes.
> (e.g. metamethods[0] is __index, metamethods[1] is __newindex, etc.)
> If the pointer is NULL, then you look in the metatable. That would be
> something Lua could manage internally when you set or modify the
> metatable.
>
> Someone would have to try it and see if there's any significant
> performance gain. It could be implemented as a compile-time option.
Yes that is what I was thinking of. In the evolution of Lua perhaps
this has already been tried, tested and discarded as not beneficial,
hence my point about possibly going over old ground.
I think there are two issues:
a) reducing the cost of lookup
b) reducing the cost of function call
The latter is much harder I suspect as any function call must go
through the Lua stack. In very specific cases maybe this could be
avoided - e.g. performing a get on an array, but in general the stack
discipline is important for the garbage collector as described in Lua
papers.
But it is a interesting problem nevertheless.
One solution is to create additional types and let the VM recognize
these types. I am particularly interested in vectors and matrices. But
at the same time I am interested in compatibility with Lua so not sure
how I can achieve both. Perhaps provide a slower metatable based
implementation for standard Lua, and a faster native implementation in
Ravi?
Regards
Dibyendu