is (a|b|c...) better than single triggers?

Posted by Pompey1 on Mon 02 Jun 2008 09:10 PM — 3 posts, 17,642 views.

#0
I think the subject says it all.

From a performance viewpoint, does anyone have an opinion on whether a single large regexp with multiple words / phrases in an or condition is more or less efficient than multiple single word / phrase triggers?

I'm thinking mainly of highlighting words / phrases, but this might extend to other issues eg sending chats / channels to a separate chat window.

Pompey1
Amended on Mon 02 Jun 2008 10:31 PM by Pompey1
Netherlands #1
Hard to say. It depends on the amount of backtracking going on and the complexity of the regular expression.

However, you don't need to worry about it. I have worlds with over 2500 triggers in them (average of 1800 enabled), all regular expressions, and the most noticable slowdowns are when I omit-from-output and echo stuff to replace it. Of course, that's how it feels - it may not be where my particular bottleneck really is.

Use whatever you like most.
Australia Forum Administrator #2
This issue came up a while ago:

http://www.gammon.com.au/forum/?id=7898

For a start, version 4.07 of MUSHclient or earlier crashed with a very long list of alternatives. Once you have version 4.08 or higher you are OK in that respect.

The developer of PCRE (the regular expression parser) advised that very long lists of alternatives were "inefficient", however as Worstje says, the performance may well be acceptable.

Breaking this into multiple triggers however does not, I think, improve efficiency, because you are now making MUSHclient do multiple trigger evaluations. In particular, if the word you want to highlight is matched in the first trigger, and you have 100 more triggers, then it will blindly go ahead and attempt to match those too.

For issues like highlighting words in another colour, you are probably best off with one long trigger.

For other things, like chat channels, it is probably more efficient to simply match on "a word" (any word), and then look that word up in a Lua table (in a script). Doing a table lookup will be more efficient than a linear scan of names. Having said that, I doubt you would have enough chat channels for the difference to be noticeable.