lua-users home
lua-l archive

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




On 07/04/15 08:07 PM, Dibyendu Majumdar wrote:
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.
Well it /could/ in theory leave the stack uninitalized and initialize/allocate as needed?

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


--
Disclaimer: these emails are public and can be accessed from <TODO: get a non-DHCP IP and put it here>. If you do not agree with this, DO NOT REPLY.