I've been thinking a long time about this, but I want to check and make sure I'm not totally off track before I do something that's going to be a pretty big undertaking.
Assume a sample size of around 500-1000 simple triggers that require no wildcards. Just plain matches. In theory/guessing, which of these is fastest?
1. Make each an individual trigger with anchored regex (^ and $).
2. Make each an individual plain text trigger, no regex.
3. Create a catchall trigger ^(.+)$ which passes its match to a function. The function uses the plain text of the match as a key in a hash table that is constructed with every one of the plain text matches of the 'triggers' as keys, and functions of what each one should do when matched (what would otherwise normally be the Send To of the trigger).
As you can probably guess, I'm here because I think 3 would be the fastest. A hash table lookup is, when best implemented, a constant time operation no matter the size of the table, and I have no reason to believe Lua is lacking in this respect.
The underlying question then is the performance of ^(.+)$. Is it slow because is can be anything, or is it fast because it can be anything? My instinct is that even if it's slow (observation seems to confirm this), it isn't so slow that its matching time plus a constant time hash table lookup is greater than the time needed to evaluate 500-1000 separate triggers.
Opinions?
Assume a sample size of around 500-1000 simple triggers that require no wildcards. Just plain matches. In theory/guessing, which of these is fastest?
1. Make each an individual trigger with anchored regex (^ and $).
2. Make each an individual plain text trigger, no regex.
3. Create a catchall trigger ^(.+)$ which passes its match to a function. The function uses the plain text of the match as a key in a hash table that is constructed with every one of the plain text matches of the 'triggers' as keys, and functions of what each one should do when matched (what would otherwise normally be the Send To of the trigger).
As you can probably guess, I'm here because I think 3 would be the fastest. A hash table lookup is, when best implemented, a constant time operation no matter the size of the table, and I have no reason to believe Lua is lacking in this respect.
The underlying question then is the performance of ^(.+)$. Is it slow because is can be anything, or is it fast because it can be anything? My instinct is that even if it's slow (observation seems to confirm this), it isn't so slow that its matching time plus a constant time hash table lookup is greater than the time needed to evaluate 500-1000 separate triggers.
Opinions?