SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Help Archive

 
 
Thread Tools Display Modes
Old 14/11/2010, 09:50 AM   #1
armyoftwo
Gangsta
 
armyoftwo's Avatar
 
Join Date: Nov 2009
Posts: 636
Reputation: 5
Default help me to optimize my code

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
__________________
- [INC] Multi language

Last edited by armyoftwo; 14/11/2010 at 10:05 AM.
armyoftwo is offline  
Old 14/11/2010, 10:26 AM   #2
Elorreli
Gangsta
 
Elorreli's Avatar
 
Join Date: Feb 2009
Location: Sweden
Posts: 709
Reputation: 162
Default Re: help me to optimize my code

http://forum.sa-mp.com/showthread.php?t=57018
__________________
New Dawn - server.dawn-tdm.com:7777

Elorreli is offline  
Old 14/11/2010, 10:28 AM   #3
Mauzen
Banned
 
Join Date: Jun 2007
Location: Western Germany
Posts: 4,880
Reputation: 1597
Default Re: help me to optimize my code

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.
Mauzen is offline  
Old 14/11/2010, 11:19 AM   #4
armyoftwo
Gangsta
 
armyoftwo's Avatar
 
Join Date: Nov 2009
Posts: 636
Reputation: 5
Default Re: help me to optimize my code

Thanks for the tips, i'm going to rescript this.
__________________
- [INC] Multi language
armyoftwo is offline  
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone know a good way to optimize this? ihatetn931 Help Archive 9 18/08/2010 09:50 PM
ServerFFS: Server is using excessive RAM, please optimize your gamemode. Arsham7 Server Support 9 29/07/2010 06:02 AM
[Help] Need Tutorials to optimize script universe Help Archive 1 22/07/2010 06:24 PM


All times are GMT. The time now is 10:32 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.