Optimizing a gamemode -
Stev - 06.09.2015
Hey,
I have been "attemping" on optimizing my gamemode, but really and truthfully. I dont know want "optimizing" is consisted of. I don't have a clue on where to start with trying to make script more functional and faster. Any tips? (For a novice person like myself)
Re: Optimizing a gamemode -
Nixtren - 06.09.2015
Hi,
I'm actually quite happy to see that someone decides to optimize his GameMode
The general rules of thumb are:
- For commands, use a ZCMD like command processor instead of the traditional strcmp
- Don't create variables with a "generic size", that is like "new string[255];", most of the times you're basically eating memory space without reason. If you are going to store the string "Hello World", use "new string [12];" (11 characters + 1 for the NUL terminator). This might help you:
http://www.kayj.ml/media/String%20Checker.php
You can create variables with the "Recommended block size", creating a variable with 12 characters or 16 would use the same memory space.
Once you feel more geeky, feel free to to read this thread:
https://sampforum.blast.hk/showthread.php?tid=580289
Also, this is not directly related to optimization, but make sure to use the plugin CrashDetect to troubleshoot errors more easily! You would be in fact optimizing your time
At last but not least, do optimizations but make sure it doesn't affect your productivity. If your code is already optimized, don't optimize it even more, because the performance gain would not be noticeable at an human scale. You get what I mean? Optimizing something to run 5 or 10 microseconds faster is what I call "overoptimization", when you could be doing something more productive.
Re: Optimizing a gamemode -
Stev - 06.09.2015
Yes, I see what you mean by "over-optimization", I will take them into consideration. I know there would be a lot more I can do to this gamemode to make it more functional its just knows the tricks (If you know what I mean). I did read that thread before posting this one but, my brain can't handle them this at this time

.
Thanks for good feedback, Will take into consideration!
Re: Optimizing a gamemode -
Nixtren - 06.09.2015
Quote:
Originally Posted by Stev
Yes, I see what you mean by "over-optimization", I will take them into consideration. I know there would be a lot more I can do to this gamemode to make it more functional its just knows the tricks (If you know what I mean). I did read that thread before posting this one but, my brain can't handle them this at this time  .
Thanks for good feedback, Will take into consideration!
|
I have just checked the filterscript you released a while ago, I would suggest:
- Use foreach (y_iterate) instead of the normal iteration (for(new i=0;i<MAX_PLAYERS;i++)) for better performance. Also, with foreach (y_iterate) you don't need to check if the player is online (IsPlayerOnline(playerid)), so one function less to call.
You're using ZCMD and sscanf, so you're not bad actually, it's already half step for a good script, just don't forget that thing about "new string[256]"
Re: Optimizing a gamemode -
Stev - 06.09.2015
Yeah, ZCMD, sscanf, Is the only things I use. I wouldn't call myself "pro", But I know much to keep myself by in what I want to do in PAWNO. I am already using foreach(...) in my gamemode currently