Please Use Event Hints

Snog

Well-known member
I just spent a good portion of a day going through add-ons that are being run on a low power server to see if I could speed things up a bit.

What I found was almost scary. :)

I found a good portion of the add-ons using code something like this in their listeners...

Code:
public static function loadClassModel($class, array &$extend)
{
  if ($class == 'XenForo_Model_Conversation')
  {
  $extend[] = 'XXXX_Model_Conversation';
  }
  else if ($class == 'XenForo_Model_Like')
  {
  $extend[] = 'XXXX_Model_Like';
  }
  else if ($class == 'XenForo_Model_AddOn')
  {
  $extend[] = 'XXXX_Model_AddOn';
  }
}

The way that's coded and entered into the listeners, that code runs on every single page load.

That really isn't bad if the only add-on running on the server is that one. But, when you multiply that by 30 to 40 add-ons it really starts accumulating.

If there were separate listeners for each one with the event hint filled in, they would only run when needed.

I was able to trim almost a full point off the server load by putting event hints in a good portion of the add-ons. But I wasn't able to hit them all.

Now I'm just as guilty as the next guy and sometimes I fail to use the event hint. But, I think we should all be thinking of them when we code. ;)
 
But, I think we should all be thinking of them when we code. ;)
I agree with this, although I do wish that multiple event hints were allowed per class. For me the issue of using event hints is not so much as forgetting them, but deciding against making multiple listener classes (I guess I might just be lazy). This might be slightly redundant to the purpose of optimizing things, but whatever.

Sounds like you're running a pretty specialized forum, my forum doesn't even have more than 6 active addons at one time. haha
 
  • Like
Reactions: Xon
I agree with this, although I do wish that multiple event hints were allowed per class. For me the issue of using event hints is not so much as forgetting them, but deciding against making multiple listener classes (I guess I might just be lazy). This might be slightly redundant to the purpose of optimizing things, but whatever.

Sounds like you're running a pretty specialized forum, my forum doesn't even have more than 6 active addons at one time. haha
I've got all of my own add-ons active on my site.

But, it's not my site that I was working on. It's a server I manage for a client. He has 30 or 40 add-ons installed.
 
I agree with this, although I do wish that multiple event hints were allowed per class. For me the issue of using event hints is not so much as forgetting them, but deciding against making multiple listener classes (I guess I might just be lazy). This might be slightly redundant to the purpose of optimizing things, but whatever.
You can make multiple events hints hit the same class, and even the same method. The real cost of event hooks is the function call, not the class name check.

But for the love of all that is holy, use a switch statement; not a if-else forest.
 
  • Like
Reactions: Naz
Top Bottom