<br>    Greg is in the right direction. When you have:<br><br>when<br>    Pattern1()<br>    Pattern2()<br>then<br>   ...<br><br>   Anytime Pattern1 change, Pattern2 beta constraints must be reevaluated. The problem in your case is that both patterns are accumulates, so they are heavier by themselves AND everytime the first one changes, the second must fully recalculate.<br>
<br>   []s<br>   Edson<br><br><div class="gmail_quote">2009/8/8 Greg Barton <span dir="ltr">&lt;<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<br>
As I understand it, the from keyword is not optimized in the way that it&#39;s output is not indexed.  Therefore if the set of objects matched changes it must rerun.  So when you have the two rules, &quot;hardConstraintsBroken&quot; is reevaluated when you change the hard constraints, and &quot;softConstraintsBroken&quot; is reevaluated when you change the soft constraints.  When there&#39;s just the one rule, it&#39;s reevaluated when either the hard or soft constraints changed, but BOTH accumulate expressions are evaluated every time.  Thus, 2x the evaluation time.<br>

<br>
--- On Sat, 8/8/09, Geoffrey De Smet &lt;<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>&gt; wrote:<br>
<br>
&gt; From: Geoffrey De Smet &lt;<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>&gt;<br>
&gt; Subject: [rules-dev] Why is this DRL twice as slow?<br>
&gt; To: <a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
&gt; Date: Saturday, August 8, 2009, 5:46 AM<br>
<div><div></div><div class="h5">&gt; Hi guys,<br>
&gt;<br>
&gt; I&#39;ve run some experiments on the DRL&#39;s used in the drools<br>
&gt; solver<br>
&gt; examination example to see how the DRL affects<br>
&gt; performance.<br>
&gt;<br>
&gt; In one experiment, I merged 2 rules into 1 rule:<br>
&gt;<br>
&gt; I changed this DRL part of examinationScoreRules.drl:<br>
&gt;<br>
&gt; rule &quot;hardConstraintsBroken&quot;<br>
&gt;          salience -1<br>
&gt;      when<br>
&gt;          $hardTotal :<br>
&gt; Number() from accumulate(<br>
&gt;          <br>
&gt;    IntConstraintOccurrence(constraintType ==<br>
&gt;<br>
&gt; ConstraintType.NEGATIVE_HARD, $weight : weight),<br>
&gt;          <br>
&gt;    sum($weight)<br>
&gt;          );<br>
&gt;      then<br>
&gt;      <br>
&gt;    scoreCalculator.setHardConstraintsBroken($hardTotal.intValue());<br>
&gt; end<br>
&gt;<br>
&gt; rule &quot;softConstraintsBroken&quot;<br>
&gt;          salience -1<br>
&gt;      when<br>
&gt;          $softTotal :<br>
&gt; Number() from accumulate(<br>
&gt;          <br>
&gt;    IntConstraintOccurrence(constraintType ==<br>
&gt;<br>
&gt; ConstraintType.NEGATIVE_SOFT, $weight : weight),<br>
&gt;          <br>
&gt;    sum($weight)<br>
&gt;          );<br>
&gt;      then<br>
&gt;      <br>
&gt;    scoreCalculator.setSoftConstraintsBroken($softTotal.intValue());<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; into this DRL part:<br>
&gt;<br>
&gt; rule &quot;constraintsBroken&quot;<br>
&gt;          salience -1<br>
&gt;      when<br>
&gt;          $hardTotal :<br>
&gt; Number() from accumulate(<br>
&gt;          <br>
&gt;    IntConstraintOccurrence(constraintType ==<br>
&gt;<br>
&gt; ConstraintType.NEGATIVE_HARD, $weight : weight),<br>
&gt;          <br>
&gt;    sum($weight)<br>
&gt;          );<br>
&gt;          $softTotal :<br>
&gt; Number() from accumulate(<br>
&gt;          <br>
&gt;    IntConstraintOccurrence(constraintType ==<br>
&gt;<br>
&gt; ConstraintType.NEGATIVE_SOFT, $weight : weight),<br>
&gt;          <br>
&gt;    sum($weight)<br>
&gt;          );<br>
&gt;      then<br>
&gt;      <br>
&gt;    scoreCalculator.setHardConstraintsBroken($hardTotal.intValue());<br>
&gt;      <br>
&gt;    scoreCalculator.setSoftConstraintsBroken($softTotal.intValue());<br>
&gt; end<br>
&gt;<br>
&gt;<br>
&gt; Now the performance for a 100 steps when from 71s to 172s,<br>
&gt; so it more<br>
&gt; then doubled.<br>
&gt; All other code stayed the same and the output (except for<br>
&gt; the times) is<br>
&gt; exactly the same.<br>
&gt; What can explain this loss in performance?<br>
&gt;<br>
&gt; --<br>
&gt; With kind regards,<br>
&gt; Geoffrey De Smet<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; rules-dev mailing list<br>
&gt; <a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
&gt;<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
rules-dev mailing list<br>
<a href="mailto:rules-dev@lists.jboss.org">rules-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-dev</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>  Edson Tirelli<br>  JBoss Drools Core Development<br>  JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>