There can be pretty huge performance gains by using OnUpdate over UNIT_HEALTH, especially in a raid setting, depending on what you plan to do.
The key to remember is that "bare" lua (without frame methods or calling other functions that you don't know what they do) is extremely fast.
You could combine the approaches:
UNIT_HEALTH:
raidNeedsUpdating[arg1] = 1
OnUpdate:
Code:
this.timer = this.timer + arg1
if this.timer > .5 then
this.timer = 0
for unit in raidNeedsUpdating do
-- this unit's health changed in last half second
-- do what you planned to do when health changed
raidNeedsUpdating[unit] = nil
end
end
That will update the health for only those that received a UNIT_HEALTH update, without doing the whole event in response to every UNIT_HEALTH.
On the distances between players, you'll probably be disappointed to find out the limitations. You can determine the distance to a unit with SpellCanTargetUnit but they *must* be in spell targeting mode (blue glowing cursor, awaiting a spell target). Otherwise you need to target a person to determine if they're in range of an ability.
The coordinates between friendly players doesn't work in instances.
edit: to take the dirty flag approach further, you could have a metatimer within the OnUpdate to stop the OnUpdates (hide the frame) after say 5 seconds of no UNIT_HEALTH happening. A frame:Show() on an already-shown frame is very fast. However I don't suggest hiding the frame every .5 seconds. Something like:
UNIT_HEALTH:
Code:
raidNeedsUpdating[arg1] = 1
this.idleTimer = 0
this:Show() -- time it! it's faster than you think
Code:
<OnLoad>
this.idleTimer = 0
this.updateTimer = 0
</OnLoad>
<OnUpdate>
this.idleTimer = this.idleTimer + arg1
this.updateTimer = this.updateTimer + arg1
if this.updateTimer > .5 then
this.updateTimer = 0
for unit in raidNeedsUpdating do
-- this unit's health changed in last half second
-- do what you planned to do when health changed
raidNeedsUpdating[unit] = nil
end
end
if this.idleTimer > 5 then
this:Hide()
end
</OnUpdate>
The above will do a health update every .5 seconds. After 5 seconds of inactivity the OnUpdate will shut down.