garrysmod icon indicating copy to clipboard operation
garrysmod copied to clipboard

TypeID and is* functions in Lua

Open Srlion opened this issue 6 months ago • 8 comments

This now should fully close https://github.com/Facepunch/garrysmod-issues/issues/4100

The only difference in behaviour is that old one (probably) doesn't use the MetaID of a userdata if it's not a gmod type? Not sure really.

Both new functions need to be placed after the new type function to work correctly.

I forgot to localize getmetatable for type function, wanted to see if it's going to make a difference, and saw around 10~15% increase in performance when benchmarking my serializing library. (basically place local getmetatable = getmetatable before this and type function)

Srlion avatar May 16 '25 05:05 Srlion

You can make the is* functions a fair bit faster by doing something similar to this.

Whether it's really worth it 🤷

aStonePenguin avatar May 16 '25 15:05 aStonePenguin

You can make the is* functions a fair bit faster by doing something similar to this.

Whether it's really worth it 🤷

I think you missed that we already getting the default type function which is the fastest you can get lol (it's already there for server/menu states on x64) https://github.com/Facepunch/garrysmod/pull/2201

I will apply a micro-optimization to make it use the Ctype function for builtin types

Srlion avatar May 16 '25 15:05 Srlion

Your Lua implementation of isentity will not work for all entities. Subclasses like Weapon and Vehicle have their own metatable and MetaName, so type will return Weapon or Vehicle for them

Zaurzo avatar May 17 '25 01:05 Zaurzo

Nice catch, will push a fix, also forgot that IsEntity exists too lul

Srlion avatar May 17 '25 05:05 Srlion

I think function isbool( v ) return v == true or v == false end will be even faster

Astralcircle avatar May 21 '25 21:05 Astralcircle

I think function isbool( v ) return v == true or v == false end will be even faster

Your right indeed, although I don't think the performance difference will matter that much but no reason to deny it 🥸

Srlion avatar May 24 '25 04:05 Srlion

I think function isbool( v ) return v == true or v == false end will be even faster

Your right indeed, although I don't think the performance difference will matter that much but no reason to deny it 🥸

So why not do this to get at least a little extra speed

Astralcircle avatar May 25 '25 17:05 Astralcircle

I think function isbool( v ) return v == true or v == false end will be even faster

Your right indeed, although I don't think the performance difference will matter that much but no reason to deny it 🥸

So why not do this to get at least a little extra speed

I thought I updated it, thanks for reminding me lol

Srlion avatar May 25 '25 19:05 Srlion

After testing this for 1 minute - it causes regression in the killfeed: image

Probably elsewhere too.

robotboy655 avatar Jul 15 '25 15:07 robotboy655

After testing this for 1 minute - it causes regression in the killfeed: image

Probably elsewhere too.

It's because you forgot to push the builtin type function clientside, told you about it on discord but just to make sure you don't forget about it: image

Srlion avatar Jul 15 '25 23:07 Srlion

Discord_2025-07-16_13-03-25

:(

Grocel avatar Jul 16 '25 11:07 Grocel

bump

bloodycop6385 avatar Jul 30 '25 15:07 bloodycop6385