SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 28/02/2018, 11:21 AM   #1
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 121
Reputation: 20
Default Profiler result's -Optimization mode

I want to optimize my gamemode and I need some help.I'm put profiler plugin on my server from 01:00 to 11:23 today,so i'm get results.

So there are picture who don't want to download:
https://i.imgur.com/dYcv4Fd.png

So if you can tell me what i need to opimize,because i'm not sure what i need to look on this profiler results.For example i don't understand this:

Quote:
operator>=(Float:,Float 1515576 6.83%
operator>(Float:,Float 1281151 3.33%

Is this much?
Quote:
floatcmp 13220491 3.75%
I use floatcmp just in one line in my mode.For afk check

Short code:

Code:
function AFKCheck(playerid)
{
	GetPlayerPos(playerid, PlayerCurrentPos[playerid][0], PlayerCurrentPos[playerid][1], PlayerCurrentPos[playerid][2]);
	if(!floatcmp(PlayerCurrentPos[playerid][0], PlayerLastPos[playerid][LastX]) && !floatcmp(PlayerCurrentPos[playerid][1], PlayerLastPos[playerid][LastY]))
	{
		PovecajPVarInt(playerid, "PlayerAFK", 1);
	}
	else
	{
		SetPVarInt(playerid, "PlayerAFK", 0);
   		AFK[playerid] = false;
	}
	PlayerLastPos[playerid][LastX] = PlayerCurrentPos[playerid][0];
	PlayerLastPos[playerid][LastY] = PlayerCurrentPos[playerid][1];
	PlayerLastPos[playerid][LastZ] = PlayerCurrentPos[playerid][2];

	if(GetPVarInt(playerid, "PlayerAFK") >= 20)
	{
          //kick(afk 20 minute)
        }
       return 1;
}

Quote:
GetSpeed 790181 8.17%
This function I use in OnPlayerUpdate( if(GetSpeed > 299) kick

Code:
GetSpeed(playerid)
{
    new Float:ST[4];
    if(IsPlayerInAnyVehicle(playerid))
    GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
    else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
    ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 178.8617875;
    return floatround(ST[3]);
}
I'm upload full .html file in attachmens.Thank you
Attached Files
File Type: rar v58.rar (15.3 KB, 10 views)
GospodinX is offline   Reply With Quote
Old 28/02/2018, 01:52 PM   #2
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,201
Reputation: 3178
Default Re: Profiler result's -Optimization mode

This is a brilliant question on how to actually do something properly, so I'm going to try go in to some depth:

1) From your results there do not appear to be any stand-out sore points. So my first question is - are you sure you need to optimise? That is an exercise for when your mode is performing very poorly and you are getting noticeable problems. Otherwise, the best way you can improve efficiency is by optimising your time and doing something else.

2) Posting an image is no use - you can't sort or inspect that.

3) As a general rule, ignore native functions and operators; there isn't much you can do about them and they are probably all from libraries. They also tend to be the things that are doing the work for your mode, so removing them is actually removing features from your game. We want to optimise when they are called, not get rid of them.

This leaves us with 3 main columns for the rest of the functions - `Calls`, `Self Time`, and `Total Time`. `Total Time` is how long a function took, including the time taken by the functions it called. `Self Time` is the time spent just in that bit of code. Improving the code in that function will bring the `Self Time` down, removing calls to other functions will bring the `Total Time` down.

Calls is very important for knowing where to spend your effort. The slowest functions in that code are functions called in `OnGameModeInit`; however, they are only called once or twice. Given that, once your mode has started optimising them is not going to make any difference - the percentage of time spent in those functions, relative to the total running time of the server, is tiny.

So let's order by `Self Time %`:

publicOnPlayerUpdate124852628.62%19.20.01.033.39%55.20.01.1

28.62% of all your execution time is spent in that just one function. Granted it is called a lot (it is the highest function for number of calls after natives and operators). `FC_OnPlayerUpdate` is second with 9.73%, so they combine to have over 1/3 of `Total Time`.

I've not seen your code, but from that I'm guessing that `OnPlayerUpdate` is a very big function on its own. This is bad for two reasons. 1) Long functions in general are not a good idea, split it up in to small, isolated, testable parts (which can then be profiled separately to find which little piece is the worst). 2) Common wisdom has always been to keep `OnPlayerUpdate` very short - there is very little that must be done there that can't be done less frequently in timers.
Y_Less is offline   Reply With Quote
Old 28/02/2018, 02:13 PM   #3
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 121
Reputation: 20
Default Re: Profiler result's -Optimization mode

First I need to say that my English is not very good,so i hope you will understand me.

1. I had some problems when i had 250+ players(for example my IC Chat is became global chat and also it was start lagg little) ->This is RP server so..I don't use Global Chat) So i'm sure that i need some optimization.Also I need to say that i don't have often a large number of players,so i don't have chance now to turn on profiler with 250+ players(I had it on celebration two years of server so there was many visitors and friends which are not our active players.)

This profiler is turn on midnight(In my time) so we don't have many players at that time .I will post tonight results also.

2.Maybe you are not see,but i'm post full .html file in attachment's.


3.I will look on OnPlayerUpdate,i have GetSpeed check,AntiChaet for Weapons and some check which I can transfer on second timer,it will be better,i think.

FC_OnPlayerUpdate is from include "fuckcleo.inc"
https://pastebin.com/AVrySvAH

So I'm not sure about it.

Thank you very much on answer!
GospodinX is offline   Reply With Quote
Old 28/02/2018, 02:25 PM   #4
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,201
Reputation: 3178
Default Re: Profiler result's -Optimization mode

I did see the HTML and downloaded it, I just mentioned the image anyway. Unfortunately, if your problem is with lots of players, a profiler result from very few players is unlikely to be representative of the problems and won't help you identify them.
Y_Less is offline   Reply With Quote
Old 08/06/2018, 07:36 PM   #5
AmigaBlizzard
Huge Clucker
 
Join Date: Jul 2012
Posts: 321
Reputation: 60
Default Re: Profiler result's -Optimization mode

I can get why you want to kick cheaters fast, but using OnPlayerUpdate is overkill.
This callback is called at least 30 times per second FOR EVERY PLAYER.
If you have 250 players online, you're executing OnPlayerUpdate 7500 times or more every second.

It won't hurt your server when you just transfer all that code to a 1-second timer.
Then that code runs 250 times per second, which is more than enough.

Optimization starts with clearing OnPlayerUpdate.
I never used that callback and I never will, because I can see no reason for any code that needs to run 30 times per second.

If someone cheats with a speed hack, kicking him within 30ms or 1 second won't make any difference, the cheater will be kicked before he can do more damage anyways.
He won't do that much extra damage in 1 second.
AmigaBlizzard is offline   Reply With Quote
Old 08/06/2018, 10:25 PM   #6
Logic_
High-roller
 
Logic_'s Avatar
 
Join Date: Jun 2015
Location: 666
Posts: 1,490
Reputation: 273
Default Re: Profiler result's -Optimization mode

Quote:
Originally Posted by AmigaBlizzard View Post
I can get why you want to kick cheaters fast, but using OnPlayerUpdate is overkill.
This callback is called at least 30 times per second FOR EVERY PLAYER.
If you have 250 players online, you're executing OnPlayerUpdate 7500 times or more every second.

It won't hurt your server when you just transfer all that code to a 1-second timer.
Then that code runs 250 times per second, which is more than enough.
Using OnPlayerUpdate as a timer is not an overkill but, a very big mistake.
I've kept my anti cheat timer to call every 1.5~2 seconds.

So for say, my timer will call 2 times in 3 seconds instead of 3. It may not make a very big difference, so why put unnecessary load?

Quote:
Originally Posted by AmigaBlizzard View Post
Optimization starts with clearing OnPlayerUpdate.
I never used that callback and I never will, because I can see no reason for any code that needs to run 30 times per second.
The only reason why anyone will use it is when they're making an Anti AFK system, since OnPlayerUpdate is not called when they are paused.

---

@OP: You can also use GetServerTickRate when you've lots of players in the daytime and let us know of the result.

PHP Code:
CMD:tickrate(playerid)
{
    new 
str[25];
    
format(strsizeof str"Server tickrate: %d."GetServerTickRate());
    
SendClientMessage(playeridCOLOR_GREYstr);
    return 
1;

__________________
Premium quality and reasonable pricing game Server hosting
Logic_ is offline   Reply With Quote
Old 21/10/2018, 04:34 PM   #7
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 121
Reputation: 20
Default Re: Profiler result's -Optimization mode

Hi guys,

I need help with optimization one my function which is very bad.This function need to count number of seconds of started event.(It shows for all players in game how much is passed seconds from the starting event)

When I start event:
Code:
        EventCount = GetTickCount();
	UpdateEvent();
	eventtimer = SetTimer("UpdateEvent",990,true);
Code:
forward UpdateEvent();
public UpdateEvent()
{
	new rTime[3];
	new string[10];
  	new TimeStamp,TotalEventTime;
  	TimeStamp = GetTickCount();
  	TotalEventTime = TimeStamp - EventCount;
  	ConvertTime(var, TotalRaceTime, rTime[0], rTime[1], rTime[2]);
  	format(string, sizeof string, "%02d:%02d",rTime[0], rTime[1]);
  	TextDrawSetString(TDEvent, string);
}
ConvertTime(used in UpdateEvent)
Code:
#define ConvertTime(%0,%1,%2,%3,%4) \
	new \
	    Float: %0 = floatdiv(%1, 60000) \
	;\
	%2 = floatround(%0, floatround_tozero); \
	%3 = floatround(floatmul(%0 - %2, 60), floatround_tozero); \
	%4 = floatround(floatmul(floatmul(%0 - %2, 60) - %3, 1000), floatround_tozero)

Profiler result for this function:

This is 4. worst function in my mode,so I want to optimize this.Maybe someone have better idea for counting number of seconds?Thanks
GospodinX is offline   Reply With Quote
Old 21/10/2018, 07:32 PM   #8
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,201
Reputation: 3178
Default Re: Profiler result's -Optimization mode

OK, that's very odd, but I think the issue here is just the number of times it gets called. There's really not much you can do to that function (except stop using arrays for normal variables, but that's a general rule everywhere). Functions called a lot will have a lot of execution time in them, simply because they are called so often, but honestly for the amount it gets called it looks fine.
Y_Less is offline   Reply With Quote
Old 21/10/2018, 08:02 PM   #9
GospodinX
Big Clucker
 
Join Date: Nov 2017
Posts: 121
Reputation: 20
Default Re: Profiler result's -Optimization mode

Ohh.
This is one-second timer,so If I convert number of calls into hours i will get: 1175 hours .
1175 hours to days = 48 days(but my mode is started only 2 days with profiler)
It's not possible. So I have mistake in mode(I have stoptimer,but maybe some time it doesn't stop.) I will test it.

2)
Quote:
except stop using arrays for normal variables, but that's a general rule everywhere
You think that I should use:
Code:
new rTime1,rTime2,rTime3 ;
instead
Code:
new rTime[3];
GospodinX is offline   Reply With Quote
Old 21/10/2018, 08:51 PM   #10
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,201
Reputation: 3178
Default Re: Profiler result's -Optimization mode

OK, yes that sounds like the timer is not being killed correctly. Actually, are you using any sort of timer fix plugin? They are notoriously inaccurate and have been known to randomly accelerate.
Y_Less is offline   Reply With Quote
Reply

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
Profiler StrikerZ Scripting Help 6 08/01/2017 04:16 PM
[Profiler result] Gamemode is generating lags Amads Scripting Help 4 14/08/2016 03:21 PM
RAM profiler Tamer Discussion 8 06/10/2015 08:23 PM
[HELP] Profiler monster010 Scripting Help 3 26/06/2014 10:41 PM
[Include] profiler.inc - plugin-less profiler Zeex_ Includes 7 04/02/2012 07:16 AM


All times are GMT. The time now is 06:16 PM.


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