help me to optimize my code
#1

http://pastebin.com/XuWCQfc3

basically all the code on there is running under 1 sec timer... i'm feeling that it will lag my server a bit.. what can i do about that?
Note: I'm using foreach there
Reply
#2

https://sampforum.blast.hk/showthread.php?tid=57018
Reply
#3

Does not look that bad. Basically, there are a lot of ifs, so 80% of the code wont be called.

Some minor-medium optimisations:

- create variables once before the foreach, not in the foreach, so that it is created again and again every time. (can make the foreachs up to 50% faster, especially for arrays like JobString[24])

- avoid checking the same variables multiple times, like
if(IsPlayerInFishZone(playerid) == 1 && GetPVarInt(playerid, "FishZone") != 1)
You can check if a player is in any FishZone first, and then differ the cases. Using switch() would also be possible, but wont give a noticeable speed boost for less than 10 cases. (This is more likely a matter of style)

- Put all the foreachs in another timer. There was a thread about this some time ago, not sure if it really is faster, but in the worst case, it will lag your server 2x for 10ms instead of one time for 20ms, which is more tolerable for your players.
Reply
#4

Thanks for the tips, i'm going to rescript this.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)