[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metatable check helper API proposal
- From: Dibyendu Majumdar <mobile@...>
- Date: Wed, 19 Aug 2020 18:10:36 +0100
On Wed, 19 Aug 2020 at 06:50, Sergey Zakharchenko
> This is a continuation of my luaL_checkudata/luaL_testudata
> optimization ideas. How about a new API, lua_metatabletopointer (or
> lua_getmetatablepointer?), acting as if lua_getmetatable followed by
> lua_topointer, but without touching the Lua stack? This would enable
> faster "are we really called with 'our' userdata?" checks and reduce
> userdata metamethod call overhead (checks would trivially extend to,
> say, a list of metatables known to a function).
In the early days of Ravi I checked performance of matrix
multiplication with Lua tables versus C arrays with metamethods.
Even without metatable checking the C arrays were slower than Lua
tables - metamethods are costly to invoke!
Adding metatable checking made it even worse of course (I was using
the optimized version suggested by Luiz in the mailing list a long
I think it is best to benchmark the perceived advantage first. You may
In Ravi today metatable based type assertion is done by the VM when
you have something like:
function tryme(a: MyType)
Having a named typed therefore turned out to be important. And for
backward compatibility it is important to continue using existing
registry of metatables.