[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Faster checking of userdata
- From: Shannon Stewman <stew@...>
- Date: Thu, 26 Aug 2004 17:30:20 -0500
On Thu, Aug 26, 2004 at 07:31:14PM -0300, Fabio Mascarenhas wrote:
> Hmm, did you benchmark this? I would be surprised if your function is
> faster than luaL_checkudata, because luaL_getmetatable uses
> lua_pushstring. This function is pretty costly, compared to lua_rawget
> and strcmp (it does a strlen and computes a hash of the string).
I did, in fact benchmark this, and it reduces the time spent in various
functions from 60% down to less than 1%. The total time spent in
fastcheckudata is around 2% of the total program time, compared with
13-15% in luaL_checkudata. It makes sense; luaL_checkudata also uses a
luaL_getmetatable, and the profiler reported that a large chunk of time
spent in luaL_checkudata was spent in strcmp.
> Your best bet is to use a light userdata to identify your metatables,
> like the other poster suggested, instead of a string.
Thank you both for the suggestion!
--
Shannon Stewman | Let us walk through the waning night,
Caught in a whirlpool, | As dawn-rays tickle our toes, the dew soothes
A quartering act: | Our blistered soles, and damp bones stir
Solitude or society? | As crimson cracks under the blue-grey sky.