The server and virtual machinery is still very very fast and the exhaustive code that kaisersouse is talking about would still take only up to XXms to execute and such cases are quite rare. Although there's always room for improvement, don't go for
premature optimization too much.
****** has made a great topic on the similar subject:
Code optimisations. I think everyone should have a look there.
The most easily understandable example I can think of right now is having code like this:
pawn Код:
for(i = 0; i < GetMaxPlayers(); i++)
{
if(IsPlayerConnected(i))
{
if(IsPlayerInAnyVehicle(i))
{
RepairVehicle(GetPlayerVehicleID(i));
}
}
}
While the loop might not be as unsophisticated when most coders write it, instead something like for(new i = 0; i != MAX_PLAYERS; i++), it still can be improved by starting to use
foreach.
pawn Код:
foreach(i : Player)
{
vID = GetPlayerVehicleID(i);
if(vID)
{
RepairVehicle(vID);
}
}
Sure, both codes are quite fast and you won't notice a thing when they execute even for hundreds of times, but it all comes down to good coding practices, which as kaisersouse mentioned, is a very important aspect of programming.
And I get carried away with my vehicle ID "optimization" talk once again while your server problem is most likely caused by another factor. Try to see if you're doing any huge file loads or MySQL operations which might have an effect on your server wholly.
kaisersouse - nice to see you back here.