<br> Jared,<br><br> Your idea is actually interesting. Although, we would need to take care of a few edge scenarios:<br><br>* The actual evaluator instance is supposed to be a "fly weight" implementation, and as so, it might be used by multiple threads. So, first thing, the cache map implementation must be thread safe. <br>
<br>* We had problems in the past when using static caches like that in JEE/Spring/OSGi environments where you have multiple modules being loaded by different classloaders etc. So, I think best would be to have a non-static map for each: the StringMatchesEvaluator and the StringNotMatchesEvaluator inner classes.<br>
<br>* We need a way to clean up the cache for no-longer used expressions. Easiest way would probably be to use an LRU map as cache. The size of the cache would probably have to be a configuration on the KnowledgeBaseConfiguration, with a given default value. This would avoid memory leaks. <br>
<br> Wanna try providing a patch for that?<br><br> Thanks,<br> Edson<br><br><div class="gmail_quote">2009/5/4 Jared Davis <span dir="ltr"><<a href="mailto:sunray@davisprogramming.com">sunray@davisprogramming.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I need some help placing a cache of compiled regular expressions using the<br>
MatchesEvaluatorsDefinition as a starting point.<br>
<br>
Just for a test I placed a static map in the class:<br>
<br>
static Map<String,Pattern> uglyHack = new HashMap<String,Pattern>();<br>
<br>
<br>
Then in each of the evaluators I have different versions of:<br>
<br>
Pattern p = uglyHack.get(value2);<br>
if (p == null ) {<br>
p = Pattern.compile(value2);<br>
uglyHack.put(value2, p);<br>
}<br>
Matcher m = p.matcher(value1);<br>
return m.matches();<br>
<br>
instead of<br>
<br>
<br>
return value1.matches( value2 );<br>
<br>
<br>
The time elapsed to inserting objects into the workspace has been cut in half.<br>
<br>
.4 seconds -> .2<br>
<br>
Has someone already done this "optimization?" Where should the cache be stored?<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>