from a performance perspective, does it make any difference whether I use
Timer-Every5.0secondsofGameTime
And select all units with the behavior "MarketGold" in a group to do something with every single one of them
or
Environment-PlayerAnyPlayerusesEffectMarketGold
And do something with the unit that cast the effect?
(The effect MarketGold is a periodic effect of the behavior MarketGold with an interval of 5 seconds)
And do you think that such things could hurt the performance hard?
For instance, I'm creating a floating text for every single unit with that behavior, the player is basically not restricted in the number of that units (even though they cost relatively much)
I mean, using the effect as an event for the trigger seems to consume more time, and that seems only logical. But putting every unit with that behavior into a unit group to do the same doesn't seem like the best solution to me either
It depends on which one is triggering an event more frequently. If there are no MarketGold effects occuring at all, the performance drop will be nil, while the periodic event will use memory regardless every 5 seconds. Conversely, if there are a lot of MarketGold effects occurring (more than once every 5 seconds,) the latter event will use more memory.
Either way, if you have a large number of units at any given time, you're going to experience performance drops. Just looking at the event structure, however, I would make this recommendation: Use loops instead of events. This will help limit the amount of memory used in event calls and should help improve performance.
Basically, have the trigger start with a single event at the beginning of the game (or whenever you want the actions to begin occurring,) then use a Repeat Forever or While loop combined with an if/then/else function and a Wait function to achieve the desired effect. In your case, I might use something like this (psuedocode):
Hmm, that seems like a very nice solution :)
Only thing I'll change is creating a global unit group variable with all the units that have the behavior in it
Seems to work flawless and fluid even with 700 (or something) of those structures on the map, though it beguns to stutter a little at 1240 (I don't think anyone would build this many, they couldn't even move..)
<<quote>>Timer - Every 5.0 seconds of Game Time
And select all units with the behavior "MarketGold" in a group to do something with every single one of them
or
Environment - Player Any Player uses Effect MarketGold<</quote>>
If you think about this from both a Game Engine perspective, and an algorithm perspective the 2nd choice is better.
Most Game Engines have an EventBus for globally signalling everything when a specific event occurs. This is very expensive because you have to notify everything that is a listener. Your first solution is constantly saying HEY EVERYBODY WE TICKED AGAIN. Your second solution is only sending signals when a Player uses that effect.
From an algorithm point of view the first one is much worse because you have to search through the Engine's QuadTree for everything [O(n)] and say HEY DO YOU HAVE THIS? The second solution is a better approach because you have the event an you can access everything in constant time.
If you have 10 players with a trigger even that causes an infinite while loop, how many instances of that trigger will run on the local players machine? Just what he triggers, or will he have instances of all events triggered regardless if it was him?
There is only 1 instance of the trigger. They will have a copy of each signaled event.
Example:
Trigger Events
Player 1 Types a Chat Message
Player 2 Types a Chat Message
etc...
Player 10 Types a Chat Message
If Player 1 enters a chat message then the event is signaled for each player. Everyone gets a copy of the event. So each player has 1 instance of it, so 10 instances were created because in this example 10 players are in the game. It doesn't matter if there is an infinite loop or not.
An event is most likely made up of:
- Name
- Any attributes like "Attacking Unit"
So basically if you have a few events that don't immediately destroy, chances are you're going to have issues with way threads are queued and causing latency spikes?
This all depends on how Blizzard is handling it. I would think Blizzard would take that into consideration, and limit the number of threads. I'm not sure how well thought out their garbage collector is, but there is a possibility of memory build up. All the locals and events are being created. You could also have a huge cpu hog from just the loop, depending on how fast it is iterating.
I honestly would not worry about this, and my best advice is just don't be stupid.
Hmm, for me the first solution seems to work best, probably because the effect get's triggered every 5 seconds from each of those buildings, and there could possibly be very many of those. When I tested, the second solution had huge lagspikes every 5 seconds at 100 buildings, while the first solution only stuttered for a little at 1200.
I did not even see this line, and this is actually why you are achieving better performance with the first option.
"And do something with the unit that cast the effect? (The effect MarketGold is a periodic effect of the behavior MarketGold with an interval of 5 seconds)"
ALL of those buildings are periodically signalling an event, versus an event being signaled once every 5 seconds. My mistake; I need to read questions more carefully :).
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Just a simple question,
from a performance perspective, does it make any difference whether I use
And select all units with the behavior "MarketGold" in a group to do something with every single one of them
or
And do something with the unit that cast the effect? (The effect MarketGold is a periodic effect of the behavior MarketGold with an interval of 5 seconds)
And do you think that such things could hurt the performance hard? For instance, I'm creating a floating text for every single unit with that behavior, the player is basically not restricted in the number of that units (even though they cost relatively much)
I mean, using the effect as an event for the trigger seems to consume more time, and that seems only logical. But putting every unit with that behavior into a unit group to do the same doesn't seem like the best solution to me either
It depends on which one is triggering an event more frequently. If there are no MarketGold effects occuring at all, the performance drop will be nil, while the periodic event will use memory regardless every 5 seconds. Conversely, if there are a lot of MarketGold effects occurring (more than once every 5 seconds,) the latter event will use more memory.
Either way, if you have a large number of units at any given time, you're going to experience performance drops. Just looking at the event structure, however, I would make this recommendation: Use loops instead of events. This will help limit the amount of memory used in event calls and should help improve performance.
Basically, have the trigger start with a single event at the beginning of the game (or whenever you want the actions to begin occurring,) then use a Repeat Forever or While loop combined with an if/then/else function and a Wait function to achieve the desired effect. In your case, I might use something like this (psuedocode):
Hmm, that seems like a very nice solution :) Only thing I'll change is creating a global unit group variable with all the units that have the behavior in it
Seems to work flawless and fluid even with 700 (or something) of those structures on the map, though it beguns to stutter a little at 1240 (I don't think anyone would build this many, they couldn't even move..)
Thank you very much!
<<quote>>
Timer - Every 5.0 seconds of Game Time And select all units with the behavior "MarketGold" in a group to do something with every single one of themor
Environment - Player Any Player uses Effect MarketGold<</quote>>
If you think about this from both a Game Engine perspective, and an algorithm perspective the 2nd choice is better.
Most Game Engines have an EventBus for globally signalling everything when a specific event occurs. This is very expensive because you have to notify everything that is a listener. Your first solution is constantly saying HEY EVERYBODY WE TICKED AGAIN. Your second solution is only sending signals when a Player uses that effect.
From an algorithm point of view the first one is much worse because you have to search through the Engine's QuadTree for everything [O(n)] and say HEY DO YOU HAVE THIS? The second solution is a better approach because you have the event an you can access everything in constant time.
@SuPa_Link: Go
A much better explanation than I was able to provide. Thanks!
If you have 10 players with a trigger even that causes an infinite while loop, how many instances of that trigger will run on the local players machine? Just what he triggers, or will he have instances of all events triggered regardless if it was him?
There is only 1 instance of the trigger. They will have a copy of each signaled event.
Example: Trigger Events Player 1 Types a Chat Message Player 2 Types a Chat Message etc... Player 10 Types a Chat Message
If Player 1 enters a chat message then the event is signaled for each player. Everyone gets a copy of the event. So each player has 1 instance of it, so 10 instances were created because in this example 10 players are in the game. It doesn't matter if there is an infinite loop or not.
An event is most likely made up of: - Name - Any attributes like "Attacking Unit"
So basically if you have a few events that don't immediately destroy, chances are you're going to have issues with way threads are queued and causing latency spikes?
@flyingspatula: Go
This all depends on how Blizzard is handling it. I would think Blizzard would take that into consideration, and limit the number of threads. I'm not sure how well thought out their garbage collector is, but there is a possibility of memory build up. All the locals and events are being created. You could also have a huge cpu hog from just the loop, depending on how fast it is iterating.
I honestly would not worry about this, and my best advice is just don't be stupid.
Hmm, for me the first solution seems to work best, probably because the effect get's triggered every 5 seconds from each of those buildings, and there could possibly be very many of those. When I tested, the second solution had huge lagspikes every 5 seconds at 100 buildings, while the first solution only stuttered for a little at 1200.
@LordJaraxx: Go
do you select all units and do your thing instantly or do you have a little wait between each unit? (wait 0.00)
@FunkyUserName: Go
I guess doing one unit per frame would decrease the performance-hit significantly, thanks for the idea :)
Edit: Wait.. no, that wouldn't work
I did not even see this line, and this is actually why you are achieving better performance with the first option.
"And do something with the unit that cast the effect? (The effect MarketGold is a periodic effect of the behavior MarketGold with an interval of 5 seconds)"
ALL of those buildings are periodically signalling an event, versus an event being signaled once every 5 seconds. My mistake; I need to read questions more carefully :).