Optimizing a gamemode
#1

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)
Reply
#2

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.
Reply
#3

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!
Reply
#4

Quote:
Originally Posted by Stev
View Post
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]"
Reply
#5

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)