[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  Programming
. -> [Folder]  General
. . -> [Subject]  Optimization

Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?
(New message)
Subject: Optimization
Name:
Your forum user name.
Register forum user name
Password:
Your forum password.
Forgotten password?
Message:
Message to be posted (in English, please)
Maximum of 6000 characters. Text only please, no HTML.
Forum codes:
Check this if your message uses 'forum codes' or templates (auto-detected for new posts).
Forum codes Templates

Save this message ...


Subject review (reverse sequence)

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 08 Mar 2012 08:35 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (18,770 posts)  [Biography] bio   Forum Administrator
Date Thu 08 Mar 2012 08:32 AM (UTC)  quote  ]
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
[Go to top] top

Posted by Malarious   (4 posts)  [Biography] bio
Date Thu 08 Mar 2012 06:32 AM (UTC)  quote  ]
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).
[Go to top] 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.


718 views.

[Reply to this subject]  Reply to this subject   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Internet Contents Rating Association (ICRA) - 2K]    [Web site powered by FutureQuest.Net]