• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Long callback execution
#1
I am getting tons of long callback executions in my server logs, People told me the that I need to shorten my functions and optimize the code. This is one of the functions that also detects long callback execution. So I'm gonna need an example from this to fix the long execution. Hoping to get some help here.?



Code:
public OnPlayerExitVehicle(playerid, vehicleid)

{

? ? ? ? InCar[playerid] = 0;

? ? ? ? LastCar[playerid] = vehicleid;



? ? ? ? if(DeliveryMan[playerid])

? ? ? ? {

? ? ? ? ? ? for(new i; i<sizeof(BurritoSpawnInfo); i)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if(GetPlayerVehicleID(playerid) == Burrito_ID[i])

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? SendClientMessage(playerid, COLOR_COURIER, "* Press Y behind your vehicle to pickup the goods.");? ?

? ? ? ? ? ? ? ? }? ?

? ? ? ? ? ? }

? ? ? ? ? ?

? ? ? ? }

? ? ? ? return 1;

}
[Image: QIDa2vB.png]

  Reply
#2
Well the question there is, how many burrito vans do you have? However, the long callback is the whole callback, so do you have any other hooks of that callback?
  Reply
#3
I wouldn't call this code terrible or something. But there is a logical error.

If you have met the condition you need, then break out of the loop.

Also you already know vehicleid so you don't need to call GetPlayerVehicleID every time.



Code:
public OnPlayerExitVehicle(playerid, vehicleid)

{

? ? ? ? InCar[playerid] = 0;

? ? ? ? LastCar[playerid] = vehicleid;



? ? ? ? if(DeliveryMan[playerid])

? ? ? ? {

? ? ? ? ? ? for(new i; i < sizeof(Burrito_ID); i)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? if(vehicleid == Burrito_ID[i])

? ? ? ? ? ? ? ? {

? ? ? ? ? ? ? ? ? ? SendClientMessage(playerid, COLOR_COURIER, "* Press Y behind your vehicle to pickup the goods.");

break;

? ? ? ? ? ? ? ? }?

? ? ? ? ? ? }

? ? ? ? ?

? ? ? ? }



? ? ? ? return 1;

}
  Reply
#4
No, that code isn't terrible at all. It is correct that there are a few minor improvements that could be made, but I didn't even bother mentioning them because they are no where near significant enough to trigger the slow code warning. That's why I asked about other hooks of the same callback, ones that might have far more code in. Alternatively, could you post the exact error from the console?
  Reply
#5
So here's something weird happening. I tried commenting the whole callback to see if it still happens and yeah, I'm still getting the warning in the console. I've checked all the includes manually to look for OnPlayerExitVehicle (except for ysi includes and mysql) and didn't find any hooks. Here's the direct code from the console
Code:
[debug] Long callback execution detected (hang or performance issue)
[debug] AMX backtrace:
[debug] #0 00003418 in ?? (0, 121, 51966748, 1598650688) in uhf.amx
[debug] #1 00003644 in ?? (0, 0, 51966780, 1598650688) in uhf.amx
[debug] #2 00004b8c in ?? () in uhf.amx
[debug] #3 00001c58 in public OnPlayerExitVehicle () in uhf.amx
[Image: QIDa2vB.png]

  Reply
#6
When you create Burrito vehicles add flag for burito vehicle and store burito id if you need

Code:
for(new i; i < sizeof(Burrito_ID); i)

{

    some_vehicle_global_var[Burrito_ID[i]]][isBurito] = true;

    some_vehicle_global_var[Burrito_ID[i]]][BuritoID] = i;

}



Then you dont need loop

Code:
public OnPlayerExitVehicle(playerid, vehicleid)

{

        InCar[playerid] = 0;

        LastCar[playerid] = vehicleid;



        if(DeliveryMan[playerid])

        {

            if(some_vehicle_global_var[vehicleid][isBurito]){

                SendClientMessage(playerid, COLOR_COURIER, "* Press Y behind your vehicle to pickup the goods.");

            }

        }



        return 1;

}
  Reply
#7
I still really don't think the problem is there. None of those calls even look like the code in your callback. But the best way to know is to recompile with `-d3`, which will allow the error message to display the full function names.
  Reply
#8
Hi. This is what I got with d3 enabled.

Code:
[debug] Long callback execution detected (hang or performance issue)

[debug] AMX backtrace:

[debug] #0 00003930 in AMX_GetEntryPrefix (E_AMX_TABLE:table=0, idx=82, &buffer=@031901bc 0, pattern=1598650688) at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_amx_impl.inc:465

[debug] #1 00003d04 in AMX_GetPointerPrefix (E_AMX_TABLE:table=0, idx=0, &buffer=@031901dc 0, pattern=1598650688) at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_amx_impl.inc:728

[debug] #2 00005644 in ScriptInit_PreInitFuncs_ () at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_core_entry.inc:173

[debug] #3 00001e50 in public OnPlayerExitVehicle () at C:\***\server\pawno\include\YSI_Data\y_foreach\..\..\YSI_Core\y_core\y_scriptinit_impl.inc:629

I believe this has to do something with the ysi includes or the amx assembly?
[Image: QIDa2vB.png]

  Reply
#9
OK, I'm not sure why but the main callback is being misreported. The good news is that this is therefore an init function and you don't need to worry about it. Try update YSI anyway, as the later versions should disable that warning in `OnScriptInit`.
  Reply
#10
(2021-05-03, 03:48 PM)Y_Less Wrote: OK, I'm not sure why but the main callback is being misreported.? The good news is that this is therefore an init function and you don't need to worry about it.? Try update YSI anyway, as the later versions should disable that warning in `OnScriptInit`.



Weird, because I am already using the latest YSI includes from the github.
[Image: QIDa2vB.png]

  Reply


Forum Jump: