Realistically, having a lot of variables isn't going to slow down your map. It might slow down development time (because you have to scroll through a bunch of variables, lol), but if you use separate variables for each trigger, then you won't have random errors.
Shared variables are useful and convenient, but you have to be careful. Here is a simple example of a time where shared variables can cause problems:
-
Kill Unit
-

Events
-


Unit - A unit starts the effect of an ability
-

Conditions
-

Actions
-


Set TempPoint = (Position of (Triggering unit))
-


Unit - Kill (Triggering unit)
-


Special Effect - Add special effect using "SomeSFXModel.mdl" at TempPoint
-


Special Effect - Destroy (Last created effect)
-


Custom script: call RemoveLocation(udg_TempPoint)
-
A Unit is Killed
-

Events
-

Conditions
-

Actions
-


Set TempPoint = (Position of (Triggering unit))
-


Unit - Order Spirit Healer 0001 <gen> to move to TempPoint
-


Custom script: call RemoveLocation(udg_TempPoint)
Seems like pretty harmless triggers, right? If you try this, it'll probably create the special effect at the center of the map. This is a really hard problem to debug, especially as you have more and more triggers in your map.
As soon as the first trigger finishes the line "Unit - Kill (Triggering Unit)", the wc3 engine jumps over to the trigger "A Unit is Killed" to evaluate the trigger. The whole trigger completes, and ultimately TempPoint is reassigned and removed. As soon as the engine finishes the "A Unit is Killed" trigger, it jumps back to the original trigger and moves on to the special effect lines. Now that TempPoint has been removed, it'll just refer to a destroyed location (which will usually give the center of the map), so the special effect will be created in the wrong area.
How do you fix it? Well, if you have the insight of what is going on, you can just move the assignment of TempPoint to be
after the "Unit - Kill unit" line. But that isn't always practical in all situations. If you use separate variables, you won't ever run into this issue. That is why we use separate variables for each trigger.
My example is a bit contrived, and I haven't actually tested it so my analysis might be untrue. But this definitely is a common issue with "For each integer..." loops, damage triggers, issuing orders, etc. That is why we made a rule that all the loops should have a dedicated looping variable, e.g.:
-
For each (SL_LoopingInteger) from 1 to 10 do (Actions)
(Integer A) and (Integer B) are also shared variables, and if you happen to run a line of code that jumps to another trigger and performs the loop, then you'll end up with weird issues.
There are actually many approaches to this issue. Technically, whenever you use a shared variable, you could just assign a
local variable to it, use the shared variable, and then clean the leak and assign it back to the local variable. But that method involves custom script and actually makes things a lot more inconvenient. As such, separating your globals is a much better idea.
(This is actually a pretty common issue in real-world programming. That is why we tend to avoid global variables. However, GUI only has access to global variables, so you have to work with what you're given)