• optimisation tricks and tips
    3 replies, posted
just wondering about the things to avoid and things that could make my code run faster thanks.
It depends what your code is doing, since code can do so many things. Some context would help.
im making a addon that has entities, weapons, custom models and custom sounds but i was just looking for overall tips and tricks
Lua uses hashmaps which are fairly fast for indexing, far faster than iterating over the entire table. Can be useful for large tables. You can create your own list of entities on both client and server using [url=http://wiki.garrysmod.com/page/ENTITY/OnRemove]ENT:OnRemove[/url] and [url=http://wiki.garrysmod.com/page/ENTITY/Initialize]ENT:Initialize[/url] rather than using [url=http://wiki.garrysmod.com/page/ents/FindByClass]ents.FindByClass[/url] (as this will just look over the entire list of entities checking if the name matches). Don't use Material in paint hooks, keep that outside of them as it only needs to be called once. Fix errors (this might sound dumb, but causing errors in hooks that are called a lot causes lag ESPECIALLY of error logging is turned on), the most common errors I've noticed with other addons and stuff are related to SWEP and ENT hooks that are called without some entity being valid anymore. There's probably more but I can't think of much that don't fall under micro-optimizations right now.
Sorry, you need to Log In to post a reply to this thread.