Chat Addon Optimization - WoWInterface
Thread Tools Display Modes
07-07-19, 12:06 AM   #1
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
Chat Addon Optimization

Good evening all. I have written a pretty extensively tested chat addon that does a lot of cool things. It adds a lot of convenient hyperlinks, and colors player names in chat, even with punctuation. It works quite well. There are no Lua errors, and everything works as I've written it. Before I begin working on modifying the "appearance" of the chat frame, I wanted to ensure that the "backend" of the chat was reasonably if not fully optimized.

The code is ~600 lines. I have documented it pretty extensively, in some cases line by line. https://pastebin.com/7sm5AnUp

Any suggestions are obviously appreciated.
  Reply With Quote
07-07-19, 12:28 PM   #2
Fishing Trainer
Seerah's Avatar
WoWInterface Super Mod
Join Date: Oct 2006
Posts: 10,800
All these table.inserts are totally unnecessary. Not only is it both a global and table lookup, but it's also a function call. At least this section of code only runs once, but it is much quicker and simpler to read if you just fill in the table when you create it.
Lua Code:
  1. local eventTable = {
  2.      'CHAT_MSG_SAY',
  3.      'CHAT_MSG_YELL',
  4.      --etc.
  5. }

Not a big deal, but why do you have two separate frames? (f and g) You only have one event registered to g, so you could just condense them. This is the whole reason why the event parameter is passed through to the function.
Lua Code:
  1. f:SetScript("OnEvent", function(self, event, ...)
  2.      if event == "UPDATE_CHAT_COLOR" then
  3.           --do this stuff here
  4.      else
  5.           --do the other stuff
  6.      end
  7. end)

Why are you calling ChatFrame_AddMessageEventFilter for all of these events and hiding all of these messages from chat? By doing this and then using your commonChatEventHandler and only adding a message to ChatFrame1, you are overriding any user's preferred location of displaying messages.
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
07-07-19, 01:00 PM   #3
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 105
Seerah, Thank you for reading and replying! Noted on eventTable and frames.

I am filtering all these events as it seemed to be the only way to modify the chat without tainting. Many chat addons don't use the filter strategy, and instead modify the AddMessage() function, which I've found taints the communities tab. If I wanted to colorize names in chat, or add hyperlinks to certain chat events that don't hyperlink the actor (like looting), I could rewrite the AddMessage() function and cause taint, or I could perform the method (as tedious as it may be) I used. As far as I can figure out, there isn't a third option, but I'm more than willing to get new information and rewrite the code.

As for the downside of always adding to ChatFrame1, yes, this is absolutely a pitfall. I haven't figured out a way to make it so the chat could show up in different tabs as the user wants quite yet, but as I keep all of my chat in the main window, it's worked for now.

Last edited by Terenna : 07-07-19 at 01:11 PM.
  Reply With Quote
08-28-19, 07:15 PM   #4
A Warpwood Thunder Caller
AddOn Author - Click to view addons
Join Date: Sep 2006
Posts: 92
It is ok to taint the chat frame. But kudos to you for spending extra time trying not to.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Chat Addon Optimization

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off