<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Arial, sans-serif; "><div><div><div>Wolfgang,</div><div><br></div><div>Unfortunately, it would be very difficult to introduce a procedural/algorithmic "branch" into the program flow.</div><div><br></div><div>Would it be possible to mimic a procedural approach within the rule using an accumulate function to extract the desired array element and then process the rest of the rule's login?</div><div><br></div><div><div><font class="Apple-style-span" color="rgb(0, 0, 0)"><font class="Apple-style-span" face="Calibri">Mike Goldner</font></font></div><div>m: 617.909.3009</div></div></div></div><div><br></div><span id="OLK_SRC_BODY_SECTION"><div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt"><span style="font-weight:bold">From: </span> Wolfgang Laun <<a href="mailto:wolfgang.laun@gmail.com">wolfgang.laun@gmail.com</a>><br><span style="font-weight:bold">Reply-To: </span> Rules Users List <<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>><br><span style="font-weight:bold">Date: </span> Friday, May 4, 2012 1:05 PM<br><span style="font-weight:bold">To: </span> Rules Users List <<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>><br><span style="font-weight:bold">Subject: </span> Re: [rules-users] Performance issues with a rule that includes LHS functions<br></div><div><br></div>Looks like an anti-pattern to me: you can expect O(n^3) effort for inserting Data facts.<br><br>This is something where a procedural/algorithmic solution is preferable to a <br>rule based solution. <br><br>-W<br> <br><br><div class="gmail_quote">
On 4 May 2012 18:44, Mike Goldner <span dir="ltr"><<a href="mailto:mike@thegoldners.com" target="_blank">mike@thegoldners.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I have a rule that is suffering severe performance degradation as I insert<br>
facts into the (stateful) session. In my simplified example, the first<br>
100 fact insertions take less than 10ms per fact. By the 1000th fact,<br>
insertions are taking about 850ms per fact. In production, the impact is<br>
much more severe, reaching 5000ms or more by the 1000th insertion. The<br>
number of facts per execution can vary from a few hundred to a few<br>
thousand.<br><br>
I've created a simplified example that demonstrates the problem: Imagine<br>
that there is a line plotted through a 3-dimensional plane and it is<br>
necessary to ensure that each plotted coordinate is an equal distance from<br>
the adjacent coordinates. I realize that the math isn't correct, but it<br>
is sufficient for the example.<br><br>
The constraint (and source of performance degradation) imposed by my data<br>
source is that the plane (X, Y, or Z) is variable and it is defined by an<br>
separate index that serves as a pointer into the coordinate list. If I<br>
remove the function calls, the problem disappears.<br><br>
Any suggestions on how I could rewrite the rule?<br><br>
Here is my rule:<br><br>
package test;<br><br>
declare Data<br>
plane : int<br>
coordinates : java.util.List<br>
end<br><br>
rule "Performance degradation with functions."<br>
dialect "mvel"<br>
when<br>
$current : Data( $currentPosition : getPosByAxis(plane, coordinates) )<br>
$before : Data( $beforePosition : getPosByAxis(plane, coordinates) <<br>
$currentPosition)<br>
not Data( getPosByAxis(plane, coordinates) > $beforePosition && <<br>
$currentPosition)<br>
$after : Data($afterPosition : getPosByAxis(plane, coordinates) ><br>
$currentPosition)<br>
not Data(getPosByAxis(plane, coordinates) < $afterPosition && ><br>
$currentPosition)<br>
eval ( ($currentPosition - $beforePosition) == ($afterPosition -<br>
$currentPosition) )<br>
then<br>
System.out.println("Rule RHS fired.");<br>
end<br><br>
function Double getPosByAxis(int plane, java.util.List coordinates) {<br><br>
return (Double) coordinates.get(plane);<br><br>}<br><br>
Thanks,<br><br>
Mike Goldner<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>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</span></body></html>