Less lag
#1

I would like to know which are the functions that might make the server laggy,And what i should prevent from using in the script to avoid getting lag and which callbacks should not be used much, And stuff on improving script and making it less laggy by the script.
Reply
#2

It's not so much about what callbacks not to use, it's all about what callback to use, where it's appropriate. And if you are using those callbacks, to check for things in a structured manner, and making sure that you use your structures correctly would be priority.

Logic, is a major portion in working with a language such as this.



This is also where copy-pasters fail, as they simply lump big segments of code together, and it ends up as a terrible mish-mash pile of crap. Then they wonder why the script is falling over, and bugging out.

Then they can't update the code for the script as they can't touch it without it falling over, because they don't understand it, then they mysteriously 'retire' releasing the script as they go.
Reply
#3

There are plenty of factors which could come in play here. One being a crappy machine which the server is hosted on.

I'd advise getting someone knowledgeable to have a look at the script if you don't know what you're doing, there's more to it than just changing a few things if you want a more performance friendly script.
Reply
#4

You could probably run the server on Raspberry PI .. It really doesn't need much. In certain callbacks you will want to check for the most common event first before going any further so you don't needlessly process any further than is strictly necessary.

Also, avoid redundancies and code repetition. I could probably write a book about all the redundancies I've seen here (and I probably should). But what is a redundancy? Basically it's checking the same thing twice (or sometimes even more). But oftentimes these things are subtle and go unnoticed. For example:
PHP Code:
if(IsPlayerInAnyVehicle(playerid))
{
    if(
GetPlayerVehicleSeat(playerid) == 0)
    {
        
// stuff
    
}

Here IsPlayerInAnyVehicle is redundant because GetPlayerVehicleSeat will only return 0 if the player is the driver of any vehicle.

Or things like checking the condition before going into a loop:
PHP Code:
if(rows)
{
    for(new 
irowsi++)
    {
        
// stuff
    
}

If there are no rows then the loop won't run because the condition (i < rows) is evaluated first (0 < 0 returning false because 0 isn't smaller than 0), thereby making the above if-statement redundant.
Reply
#5

You should check which part of script is causing lag.
A little Tip
Many people do GetPlayerName when ever they need the name. But the best way is simply storing player name in a string and using it when needed.
Reply
#6

Optimizations that make an insignificant difference like the ones above does not define a laggy script.

Quote:
Originally Posted by Vince
View Post
Or things like checking the condition before going into a loop:
PHP Code:
if(rows)
{
    for(new 
irowsi++)
    {
        
// stuff
    
}

If there are no rows then the loop won't run because the condition (i < rows) is evaluated first (0 < 0 returning false because 0 isn't smaller than 0), thereby making the above if-statement redundant.
True, but there are scenarios when the if-then is required (to run additional code basically such as a message).
Reply
#7

Quote:
Originally Posted by CheezIt
View Post
Optimizations that make an insignificant difference like the ones above does not define a laggy script.
What you think is an "insignificant difference" has the potential, left unchecked, of crashing the server, and causing player disconnects.
Reply
#8

Quote:
Originally Posted by Sew_Sumi
View Post
What you think is an "insignificant difference" has the potential, left unchecked, of crashing the server, and causing player disconnects.
Doing this:
Quote:
Originally Posted by Vince
Code:
if(IsPlayerInAnyVehicle(playerid))
{
    if(GetPlayerVehicleSeat(playerid) == 0)
    {
        // stuff
    }
}
This:
Quote:
Originally Posted by Vince
Code:
if(rows)
{
    for(new i; i < rows; i++)
    {
        // stuff
    }
}
And/or this:
Quote:
Originally Posted by coool
Many people do GetPlayerName when ever they need the name. But the best way is simply storing player name in a string and using it when needed.
Will not make your script less laggy at a point where it's noticeable.

Maybe we have different definitions of laggy, but mine is more to the extent where there's actual shudders. And I don't see how doing said optimizations will make it less crash-sensitive. But don't misinterpret me, I do understand where they are coming from.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)