Most efficient way to handle this?

Post Reply
dicene
Posts: 47
Joined: Thu Sep 25, 2014 7:36 am

Most efficient way to handle this?

Post by dicene »

Problem: I'd like to replicate the function of Aetolia's config option to display generic combat messages(example: Person uses FERALITY SLASH at Person.) I like the well-written combat messages in IRE games, but having generic messages would make a lot of my coding in Imperian easier. The message farming to make this a thing will take a while, but I'll get it done in time. My focus at the moment is starting to build up the system itself, and in such a manner that I can easily add new messages or replace old ones as they come up. As an overzealous estimate, I'd say each skillset will be roughly 15 messages, and there are close to 60 skillsets. So on the high end, I'm guessing 900 messages. It could easily be a quarter of that, but I want to code it in a manner that 900 is possible without extremely long processing times. The very largest combat scenario I expect to be in would be 12v12, and those are rare, but I want to build the system in a manner where that's doable. We're looking at between 3-10 lines of code from each combo, at an average of around 2.5s between combos. Worst case that's 24*10/2 = 96 lines of code a second at the very most. 96 lines per second, 900 messages, so at the very worst case 86400 regex parses a second in the very worst case.

I don't have the willpower to hand write 900 triggers in the GUI, so I want an approach that lets me add messages and handle them one at a time to a file or table in a script then handle it from there. As a quick test I ran a sample pattern through both the built in string.match() and through a compiled regex through the rex table that gives you access to the PCRE bit of Lrexlib. On this abysmal computer, 86400 of the sample PCRE match was 0.439s, 86400 of the Lua Patterns match was 0.12s.

0.12s at worst case scenario would be close to acceptable, but I am hesitant to use Lua's Match as I want to use named captures with these so I don't have to do any complicated code(or spend a lot of time) sorting each trigger by what variables they capture and which order they'll be in(might have user first then target, might be the other way around), and as far as I know, there is no way to return named captures from a string.match() call.

I know I can build the system the way I want by matching regex on every single line, but it looks like that will likely be too slow. I know I do not want to write out a trigger for each message in the GUI. I've considered generating tempRegexTriggers on startup for each message, but I don't know what kind of a real speed gain I'll get from letting Mudlet handle the triggers instead of triggering every line with a lua function of "return true".

Questions:
If using lua patterns would be quicker in the long run, is there a method of returning named captures that I'm unaware of?
Would tempTriggers have a significantly increased speed over parsing every line manually with pre-built regexes?

Edit: For reference, these are the example tests I'm using. They're pretty indicative of kind of messages I'm parsing:
Code: [show] | [select all] lua
local re = rex.new([[^(\w+) balls up one fist and hammerfists (\w+)\.$]])
local lre = [[^(%w+) balls up one fist and hammerfists (%w+)%.$]]

string.match(lre, "Person balls up one fist and hammerfists you.")
  _, _, r = {re:exec("Person balls up one fist and hammerfists you.")}

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Most efficient way to handle this?

Post by Vadi »

I used a combination of GUI triggers (which are pretty easy to do since triggers accept multiple patterns) and temp* functions to build the system I do.

Lua patterns are quicker because they are simpler. You could always create two sets of triggers for the possible combinations you might have.

User avatar
SlySven
Posts: 1019
Joined: Mon Mar 04, 2013 3:40 pm
Location: Deepest Wiltshire, UK
Discord: SlySven#2703

Re: Most efficient way to handle this?

Post by SlySven »

Vadi wrote:...triggers accept multiple patterns...
50 I believe from the last time I looked in that area...

User avatar
Vadi
Posts: 5035
Joined: Sat Mar 14, 2009 3:13 pm

Re: Most efficient way to handle this?

Post by Vadi »

Yeah... (?) You can always create another for more.

icesteruk
Posts: 287
Joined: Sun Jan 20, 2013 9:16 pm

Re: Most efficient way to handle this?

Post by icesteruk »

Vadi wrote:Yeah... (?) You can always create another for more.
Or Create one per class Incase Admin change a line your not at a lost as to find WHICH trigger 'file' the trigger is in..

Post Reply