Matches performs a regex comparison which is likely to be more expensive to perform.
Either of the following may (or may not) improve performance.
Use a single matches, eg String(this matches
"TextString1|TextString2|TestString3")), this would at least make it a single
operation.
Also have you tried just using ==, eg exists( String(this == "TestString1") ||
String(this == "TestString2") || String(this == "TestString3") from
DclassesList)
You may also want to consider whether it would be beneficial to restructure your fact
class to get rid of the from, and match against ClassName facts instead - this may give
you a big performance gain as it means each rule wouldn't have to iterate over the
list, if you are updating MyContext then this gain is likely to be even bigger.
Thomas
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Kumar Pandey
Sent: 29 September 2010 15:17
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Matching strings in two arrays
Drools 5.1.0
I have a need to match list of incoming strings to those in the rule. All the strings in
the fact object needs to exists in the rule.
I have a large set of rules around 5000.
In general I have around 4 conditions per rule and its taking in average around 30- ~40 ms
to go through the 5000 rules.
However the following construct that I am using to match the incoming set of input strings
is adding on the average 200ms to rules execution.
Is there a more efficient way to do this?
MyContext is the fact class and classes is array of String.
I need to make sure that the classes array contains all three strings TestString1,
TestString2 and TestString3.
MyContext(DclassesList : classes)
exists( String(this matches "TestString1") || String(this matches
"TestString2") || String(this matches "TestString3") from
DclassesList)
Of course each rule in the 5000 can have diff set of strings to match.
Thanks
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************