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, 10:21 AM   #1
GospodinX
Little Clucker
 
Join Date: Nov 2017
Posts: 26
Reputation: 0
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, 8 views)
GospodinX is offline   Reply With Quote
Old 28/02/2018, 12:52 PM   #2
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,677
Reputation: 3062
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, 01:13 PM   #3
GospodinX
Little Clucker
 
Join Date: Nov 2017
Posts: 26
Reputation: 0
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, 01:25 PM   #4
Y_Less
Spam Machine
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 14,677
Reputation: 3062
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
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 03:16 PM
[Profiler result] Gamemode is generating lags Amads Scripting Help 4 14/08/2016 02:21 PM
RAM profiler Tamer Discussion 8 06/10/2015 07:23 PM
[HELP] Profiler monster010 Scripting Help 3 26/06/2014 09:41 PM
[Include] profiler.inc - plugin-less profiler Zeex_ Includes 7 04/02/2012 06:16 AM


All times are GMT. The time now is 09:28 PM.


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