Quick Server Load Question

So in term of Load/Stress on the ‘Workshop Server’, it’s better to Modify a variable vs. Setting a variable. Correct?

Example: Set a Variable to Players with Radius.
“do something with that”

Now, Set variable to Players w/ Radius?
OR
Mod Var, Remove from Array, players who’s distance is greater then the specified radius?

actions
{
Event Player.E = Filtered Array(Players Within Radius(Event Player.F[0], Event Player.D, Opposite Team Of(Team Of(Event Player)),
Surfaces), Is Alive(Current Array Element) == True);
}

OR

actions
{
Modify Player Variable(Event Player, E, Remove From Array By Value, Filtered Array(Event Player.E, Distance Between(
Event Player.F[0], Current Array Element) > Event Player.D));
}

I mean, both work just fine…and chances are the difference in load (if there is any) is negligible at best… but just out of curiosity.

1 Like

i believe so, i’m not very good with stuff like this but i’d choose the one that doesn’t overload the server as quickly/much

I would also like to know this.

Setting or storing a variable has a lower impact than updating a variable with modify instruction, depending when you choose to do either, is it coupled with an Array( so how much of data is affected) and how often you do this.

2 Likes

Lets break this down:

Players Within Radius(Event Player.F[0], Event Player.D, Opposite Team Of(Team Of(Event Player)), Surfaces)
The opposing team has 6 players at max, so it is 6 operations worst case + 6 operations for creating the new temporary arrays.

Filtered Array(Players Within Radius(...), Is Alive(Current Array Element) == True)
Worst case 6 players → 6 times checking the alive status + 6 operations for the creation of the new arrays.

So 24 operations total.

Filtered Array(Event Player.E, Distance Between(Event Player.F[0], Current Array Element) > Event Player.D)
Again, 6 players in the worst case → 6 operations + 6 for the array creations.

Modify Player Variable(Event Player, E, Remove From Array By Value, Filtered Array(...));
This is a bit different. The worst case is that the filtered array returns all 6 players [p1, p2, p3, p4, p5, p6] and that the Event Player.E array are all 6 players but in reverse order [p6, p5, p4, p3, p2, p1]. So the first operation (remove p1) would take 6 operations to find p1, then 1 operation to create a new array. The second operation would then take 5 operations to find p2, then 1 to create a new array. That makes 7 + 6 + 5 + 4 + 3 + 1 = 26 operations.

So 38 operations total.

Of course, these are abstract numbers, but I’d consider the first method faster in the worst case scenario.

Why not use method 3:

Event Player.E = Filtered Array(Opposite Team Of(Team Of(Event Player)), Is Alive(Current Array Element) && Distance Between(Event Player.F[0], Current Array Element) <= Event Player.D));

Opposing team has 6 players max and for each player there is 1 operation to check alive status, 1 operation to check distance and 1 array creation operation, so 3 * 6 = 18 total.

Note: Since memory access operations have a much higher impact on performance than just arithmetic operations, I only considered those. Also, function calls do include memory operations, but since I can not tell how many function calls there are happening in the background, I ignored the function call overhead aswell.

2 Likes

Could be that the backend is c/c++, depending which compiler is used, there can be or is some adjustment made.

2 Likes

Wow thx for the detailed reply. Lol haven’t been here for a few days so Srry for ‘this’ late reply…
If im understanding your explanation right, it seems your comparing the number of operations the server goes through to preform an action/command to server load. Ok, that makes since. Bigger number = more load/stress.
Couple things i’ve noticed throughout the years of playing with this workshop, (and to be fair, maybe these are niche occurrences)

  1. Players w/in Radius has a ‘built in’ LOS feature. Where as Distance Between doesn’t. Thus, for Method 1 & 3 to be equal, you’d have to add “Is in LOS, F[0], current array element”. So that would add another 6? operations to your Method 3?

  2. the Distance Between action causes higher server load then Player’s w/in Radius.
    Example:
    Condition: Players w/in Radius (eventplayer) 10 = True
    Action: play effect
    Vs.
    Condition: Distance Between (eventplayer) all players < 10
    Action: Play effect
    (this will cause the server load to skyrocket in a 6v6 scenarios)

Now granted, this is used in a condition that’s being checked constantly, where as in an action sequence, it’s being evaluated once, but it’s always left me feeling Distance Between is a more resource hog…

Anyways, thx again for the reply. I’ll try to incorporate method 3 more often if i can.

Yea it might be the case that one “players within radius” is faster than “filtered array(players, distance between)” since the first is optimized internally.

I was just comparing runtime complexity, because I felt motivated to do so.

And I wanted to point out that remove from array by value should have a bad performance, since it needs to loop over the array to find the value first before actually removing the entry.