Optimizing PreDrawHalos

So I have the PreDrawHalos hook loop through all the players, and depending on their team / class / whatever they are grouped into tables and are drawn with different colored halos.
The problem is, this leads to 3 halo.Add calls, and this lags down the game.

If I remove two of them, it’s fine, but the more I add back the laggier it is, even if the players in the table are not visible. So I tried if v:Visible() == true to see if they are actually visible, but that’s only severside… oops. But that could be just what I need to optimize it .

You can network the visibility, although that would probably not help the efficiency too much

Would it be possible to merge it all into one halo.Add call? Even when the tables for 2 of the calls are completely empty, it still lags exactly the same amount… so checking if players are visible won’t help any way. But the thing is I want one group of players to be highlighted in green and seen through walls, one group highlighted in blue and not seen through walls, and one highlighted in red not seen through walls.

Halos are slow, if you use them too much you’re going to encounter issues.

The optimizations you suggest sound like things the engine should do.

Entity:IsLineOfSightClear would work.

This is a more optimised version of halos made using stencils: http://facepunch.com/showthread.php?p=39671972#post39671972. The author mentions it doesn’t work on players but this was a couple of years ago so it may have been fixed (and looking at the wiki gives me the impression that is).

I optimized it, now I hardly get an FPS drop. For anyone else who wants to optimize I just made it so it only updates the table of players every 30 frames.