Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ Programming
➜ General
➜ Optimization
It is now over 60 days since the last post. This thread is closed.
Refresh page
| Posted by
| Malarious
(4 posts) Bio
|
| Date
| Thu 08 Mar 2012 06:32 AM (UTC) |
| Message
| So I am helping someone update their script and I wanted to check a few things since this falls to the internals really.
1) When you have a trigger like this:
^(Hi how are you|hello how are you|yo whats up)\.$
Does Mushclient basically do 3 seperate evaluations for this? So would it be faster to do like.. ^(\w+ how are you)\.$ and then a second trigger or is the above the fastest option?
2) Similar to one when a trigger uses options like (him|her) for instance...
Happily, (he|she) gives you a warm smile.
Is it faster to use that or \w+ instead?
3) If a trigger looks something like this.....
^You try to cleanse your aura (.*)\.$
Does that only evaluate once? So then you could put if "%1" == "but nothing happens" then
blah
elseif "%1" == "and you feel your body purged of disease" then
Wondering how efficient that option is, given it can match on alot of things but that is ok. Would that still mean 1 trigger that could match alot of related lines for the sake of processing?
4) Last one!
Right now I know some people use toggles based on a characters class... for instance whether you need to cast heal or sip healing. Right now that looks like...
if GetVariable("healer") == "cast healing" then
Send("cast healing")
else
Send("sip healing")
end
In an effort to get rid of comparisons (in some instances there can be 4 or more if's involved) would it be more efficient to change it to something like...
Execute(GetVariable("healer"))
On the theory that it would do a lookup and do it right now instead of making a checkup and then calling based on a tree?
Hopefully those all make sense, one of the Iron Realms Games has enormous systems and we are trying to shave time off the processing (1700 triggers right now looking to cut back). | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #1 on Thu 08 Mar 2012 08:32 AM (UTC) |
| Message
|
Quote:
1) When you have a trigger like this:
^(Hi how are you|hello how are you|yo whats up)\.$
Does Mushclient basically do 3 seperate evaluations for this? So would it be faster to do like.. ^(\w+ how are you)\.$ and then a second trigger or is the above the fastest option?
It passes the trigger to the PCRE regexp engine. It does that once. I think it would be faster to leave that as it is, as that is one regexp call rather than three.
Quote:
2) Similar to one when a trigger uses options like (him|her) for instance...
Happily, (he|she) gives you a warm smile.
Is it faster to use that or \w+ instead?
I would leave that alone (subject to testing), but you really need to think about how quickly the regexp can *fail* rather than how quickly it passes. For example, a line that doesn't start with "Ha" will fail immediately, so the test for he/she doesn't need to be done. If you make that two triggers it has to test that twice.
Quote:
3) If a trigger looks something like this.....
^You try to cleanse your aura (.*)\.$
Does that only evaluate once?
Yes, of course. All triggers are evaluated once. For something like 1000 auras it is probably best to use what you had there and then do a Lua table look-up of the exact aura (table lookups are fast).
Quote:
In an effort to get rid of comparisons (in some instances there can be 4 or more if's involved) would it be more efficient to change it to something like...
Execute(GetVariable("healer"))
What would be more efficient is to get that MUSHclient variable into a Lua variable. eg.
healer = GetVariable "healer"
if healer == "y" then
Send("cast healing")
else
Send("sip healing")
end
But of course this is only efficient if you need to do the test more than once. In fact if you need to know true/false "is he a healer?" then you might do:
ishealer = GetVariable "healer" == "y" -- make a boolean
if ishealer then
Send("cast healing")
else
Send("sip healing")
end
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
| Posted by
| Nick Gammon
Australia (23,173 posts) Bio
Forum Administrator |
| Date
| Reply #2 on Thu 08 Mar 2012 08:35 AM (UTC) |
| Message
| | You can also make things more efficient by giving triggers that are likely to occur often (eg. prompt lines) a lower sequence so they are evaluated first. That way it doesn't have to match 1000 low-priority triggers every time a prompt arrives. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
13,763 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top