-
Notifications
You must be signed in to change notification settings - Fork 334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce index calls on EGP:ValidEGP #2962
Conversation
If indexing is a problem, couldn't you take the functions from the metatable directly and just use those? |
local class = Ent:GetClass() | ||
return class == "gmod_wire_egp" or class == "gmod_wire_egp_hud" or class == "gmod_wire_egp_emitter" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of GetClass, we can set a variable to each of these entities, ENT.IsEGP = true
and check Ent.IsEGP
It will invoke __index still unless you localize GetTable or GetVar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this, thanks for the suggestion
I'd like to fix the linting issues in this file. I could do it in this PR while I'm here, or I could do it in a followup PR - up to you 👍 |
|
function EGP:ValidEGP( Ent ) | ||
return IsValid( Ent ) and (Ent:GetClass() == "gmod_wire_egp" or Ent:GetClass() == "gmod_wire_egp_hud" or Ent:GetClass() == "gmod_wire_egp_emitter") | ||
do | ||
local GetTable = FindMetaTable( "Entity" ).GetTable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add local IsValid = FindMetaTable( "Entity" ).IsValid
? I'm also curious if this function returns false if nil is passed into it or if it errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it errors, then replace IsValid( ent )
with ent and IsValid( ent )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It handles nil
:
lua_run print( FindMetaTable( "Entity" ).IsValid( nil ) )
> print( FindMetaTable( "Entity" ).IsValid( nil ) )...
false
Applied 👍
Simple optimization to reduce entity
__index
calls for this commonly-used method.With only a few EGPs out, I recorded 77,762
__index
calls from this method over a 10 second sample.Also, from a high-level skim, it seems like this could even be cached on the EGP entity itself to make it even faster.