<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=Generator content="Microsoft Word 12 (filtered medium)">
<!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]-->
<style>
<!--
/* Font Definitions */
@font-face
        {font-family:宋体;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:宋体;
        panose-1:2 1 6 0 3 1 1 1 1 1;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:"\@宋体";
        panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0cm;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
h4
        {mso-style-priority:9;
        mso-style-link:"标题 4 Char";
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:宋体;
        font-weight:bold;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
code
        {mso-style-priority:99;
        font-family:宋体;}
p.MsoAcetate, li.MsoAcetate, div.MsoAcetate
        {mso-style-priority:99;
        mso-style-link:"批注框文本 Char";
        margin:0cm;
        margin-bottom:.0001pt;
        font-size:9.0pt;
        font-family:"Times New Roman","serif";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
span.4Char
        {mso-style-name:"标题 4 Char";
        mso-style-priority:9;
        mso-style-link:"标题 4";
        font-family:宋体;
        font-weight:bold;}
p.title, li.title, div.title
        {mso-style-name:title;
        mso-margin-top-alt:auto;
        margin-right:0cm;
        mso-margin-bottom-alt:auto;
        margin-left:0cm;
        font-size:12.0pt;
        font-family:宋体;}
span.Char
        {mso-style-name:"批注框文本 Char";
        mso-style-priority:99;
        mso-style-link:批注框文本;
        font-family:"Times New Roman","serif";}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:612.0pt 792.0pt;
        margin:72.0pt 90.0pt 72.0pt 90.0pt;}
div.WordSection1
        {page:WordSection1;}
-->
</style>
<!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="2050" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang=ZH-CN link=blue vlink=purple>
<div class=WordSection1>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Hi, Wolfgang,<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'>I think I’ve figured out some answers and see my shares below. Thanks
and let me know your thoughts about #3.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Best<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'>Abe<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<p style='margin-left:18.0pt'><span lang=EN-US>1.</span><span lang=EN-US
style='font-size:7.0pt'> </span><span
lang=EN-US>Will I gain better performance if I put the rule differentiator
condition </span><span style='font-family:宋体'>“</span><span lang=EN-US>compareToPostThreshold($txn)==2</span><span
style='font-family:宋体'>”</span><span lang=EN-US> at the beginning of both rule
1 and 2? <o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>One kind pf Rete optimization is based on
evaluating common constraints once, therefore: no.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'>//Abe: it definitely
makes a difference if you put differentiator conditions at the beginning – this
way RETE won’t waste efforts constructing networks which will not fulfill. See
below example.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'>rule "Evaluation
of assignment in r-value position"<br>
no-loop true<br>
when<br>
$statement:CStatement($value:value)<br>
eval(Matcher.isRVExpression($value))<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'> eval(0==Matcher.getClauseNum())<br>
then<br>
System.out.println($value);<br>
modify($statement){<br>
setSemantics(Matcher.getRVSemantics(memory,$value));<br>
}<br>
end<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'>rule "Evaluation
of assignment clause in r-value position without updating memory"<br>
no-loop true<br>
when<br>
$statement:CStatement($value:value)<br>
eval(Matcher.isRVExpression($value))<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'> eval(0<Matcher.getClauseNum())<br>
then<br>
System.out.println("=="+$value);<br>
Matcher.decreaseClauseNum();<br>
modify($statement){<br>
setSemantics(Matcher.getRVSemanticsWithoutUpdate(memory,$value));<br>
}<br>
end<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'><o:p> </o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'>These two rules try
to validate if Matcher.getClauseNum() ==0 or <0. If you put differentiator “Matcher.getClauseNum()”
at the end of LHS, Drools will start two threads to deduct RETE network so even
if the fact hits rule 1, rule 2 will still be stepped in. But if we make the
two rules as below, RETE will identify the shortcut correctly and no thread
will be triggered to step into rule 2:<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'><o:p> </o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US style='color:#548DD4'>rule "Evaluation of assignment in r-value
position"<br>
no-loop true<br>
when<br>
eval(0==Matcher.getClauseNum())<br>
$statement:CStatement($value:value)<br>
eval(Matcher.isRVExpression($value))<br>
then<br>
System.out.println($value);<br>
modify($statement){<br>
setSemantics(Matcher.getRVSemantics(memory,$value));<br>
}<br>
end<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US style='color:#548DD4'>rule "Evaluation of assignment clause in
r-value position without updating memory"<br>
no-loop true<br>
when<br>
eval(0<Matcher.getClauseNum())<br>
$statement:CStatement($value:value)<br>
eval(Matcher.isRVExpression($value))<br>
then<br>
System.out.println("=="+$value);<br>
Matcher.decreaseClauseNum();<br>
modify($statement){<br>
setSemantics(Matcher.getRVSemanticsWithoutUpdate(memory,$value));<br>
}<br>
end<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'><o:p> </o:p></span></p>
<p style='margin-left:18.0pt'><span lang=EN-US>2.</span><span lang=EN-US
style='font-size:7.0pt'> </span><span
lang=EN-US>I saw salaboy</span><span style='font-family:宋体'>’</span><span
lang=EN-US>s video claiming that to avoid using eval() in the rule. Do we have
any alternative way to do that from a performance consideration<o:p></o:p></span></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-US>Constraints
based on fields using == are best. Other things may result in eval-like
evaluations anyway. Most of the time, it isn't eval that causes performance
setbacks.<o:p></o:p></span></p>
<p style='margin-left:18.0pt'><span lang=EN-US>or I</span><span
style='font-family:宋体'>’</span><span lang=EN-US>d better collect/ prepare all
the data before I send them into the session?<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>Not clear what you mean by this, but if you
can provide attributes that lend themselves to straightforward constraints it
might be worthwhile considering some up-front processing of facts.<br>
<span style='color:#548DD4'> //Abe: I saw below statement from Drools
document 5.2.0. As Eval is not indexed, overuse of evale reduces the rules’
clarity and will result in a bad performance.<o:p></o:p></span></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span
lang=EN-US style='font-family:宋体;background:yellow;mso-highlight:yellow'>5.8.3.7. Conditional
Element eval<o:p></o:p></span></b></p>
<p class=MsoNormal align=center style='text-align:center'><span lang=EN-US
style='font-family:宋体'><img width=313 height=19 id="图片_x0020_1"
src="cid:image001.png@01CCC420.7881ECC0" alt=eval></span><span lang=EN-US
style='font-family:宋体;background:yellow;mso-highlight:yellow'><o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><b><span
lang=EN-US style='font-family:宋体;background:yellow;mso-highlight:yellow'>Figure 5.29. eval</span></b><span
lang=EN-US style='font-family:宋体;background:yellow;mso-highlight:yellow'><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-family:宋体;background:yellow;
mso-highlight:yellow'><o:p> </o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US style='font-family:宋体;background:yellow;mso-highlight:yellow'>The
conditional element eval is essentially a catch-all which allows any semantic
code (that returns a primitive boolean) to be executed. This code can refer to
variables that were bound in the LHS of the rule, and functions in the rule
package. Overuse of eval reduces the declarativeness of your rules and can
result in a poorly performing engine. While eval can be used anywhere in the
patterns, the best practice is to add it as the last conditional element in the
LHS of a rule.<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US style='font-family:宋体;background:yellow;mso-highlight:yellow'>Evals
cannot be indexed and thus are not as efficient as Field Constraints. However
this makes them ideal for being used when functions return values that change
over time, which is not allowed within Field Constraints.</span><span
lang=EN-US style='font-family:宋体'><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p style='margin-left:18.0pt'><span lang=EN-US>3.</span><span lang=EN-US
style='font-size:7.0pt'> </span><span
lang=EN-US>What</span><span style='font-family:宋体'>’</span><span lang=EN-US>s
you guys</span><span style='font-family:宋体'>’</span><span lang=EN-US> naming
convention for rule</span><span style='font-family:宋体'>’</span><span
lang=EN-US>s salience?<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US>Not clear what you mean by that.<o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='color:#548DD4'>//Abe: I mean how do
you weight your salience values across different rules. I’ve seen various styles
in my project – somebody uses 100, 200, 300 but somebody uses 90, 100, 110,
120, etc. This is not a big problem as they are working on different rules and
won’t pollute each other. However I would still try to make it consistent so
maintain each other’s rule files will be easier…</span><span lang=EN-US
style='font-size:10.5pt;font-family:"Calibri","sans-serif";color:#548DD4'><o:p></o:p></span></p>
<p class=MsoNormal><span lang=EN-US style='font-size:10.5pt;font-family:"Calibri","sans-serif";
color:#1F497D'><o:p> </o:p></span></p>
<div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm'>
<p class=MsoNormal><b><span style='font-size:10.0pt;font-family:宋体'>发件人<span
lang=EN-US>:</span></span></b><span lang=EN-US style='font-size:10.0pt;
font-family:宋体'> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] </span><b><span style='font-size:
10.0pt;font-family:宋体'>代表 </span></b><span lang=EN-US style='font-size:10.0pt;
font-family:宋体'>Wolfgang Laun<br>
</span><b><span style='font-size:10.0pt;font-family:宋体'>发送时间<span lang=EN-US>:</span></span></b><span
lang=EN-US style='font-size:10.0pt;font-family:宋体'> 2011</span><span
style='font-size:10.0pt;font-family:宋体'>年<span lang=EN-US>12</span>月<span
lang=EN-US>26</span>日<span lang=EN-US> 22:20<br>
</span><b>收件人<span lang=EN-US>:</span></b><span lang=EN-US> Rules Users List<br>
</span><b>主题<span lang=EN-US>:</span></b><span lang=EN-US> Re: [rules-users]
Performance consideration in rule writing<o:p></o:p></span></span></p>
</div>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
<p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-US>See below.<o:p></o:p></span></p>
<div>
<p class=MsoNormal><span lang=EN-US>2011/12/26 Zhuo Li <<a
href="mailto:milanello1998@gmail.com">milanello1998@gmail.com</a>><o:p></o:p></span></p>
<div>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>Hi, team,<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> <o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>I have some quick questions here regarding performance best
practices of rule writing. See below two pieces of rules:<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> <o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>Rule “1”<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> Salience 100<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> No-loop true<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> When $txn :
data(sourceid ==
5&&txnjustify==”995”&&eval(creditOption($txn)==1)&&eval(isGCSwitch($txn))&&isCurrencyEquals($txn)==0&&compareToPostThreshold($txn)==2);<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> Then<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>
…<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> End<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> <o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>Rule “2”<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> Salience 100<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> No-loop true<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> When $txn :
data(sourceid ==
5&&txnjustify==”995”&&eval(creditOption($txn)==1)&&eval(isGCSwitch($txn))&&isCurrencyEquals($txn)==0&&compareToPostThreshold($txn)==1);<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> Then<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>
…<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> End<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> <o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>Questions:<o:p></o:p></span></p>
<p style='margin-left:18.0pt'><span lang=EN-US>1.</span><span lang=EN-US
style='font-size:7.0pt'> </span><span
lang=EN-US>Will I gain better performance if I put the rule differentiator
condition </span><span style='font-family:宋体'>“</span><span lang=EN-US>compareToPostThreshold($txn)==2</span><span
style='font-family:宋体'>”</span><span lang=EN-US> at the beginning of both rule
1 and 2? <o:p></o:p></span></p>
</div>
</div>
<div>
<p class=MsoNormal><span lang=EN-US>One kind pf Rete optimization is based on
evaluating common constraints once, therefore: no.<br>
<o:p></o:p></span></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;
margin-left:4.8pt;margin-right:0cm'>
<div>
<div>
<p style='margin-left:18.0pt'><span lang=EN-US>2.</span><span lang=EN-US
style='font-size:7.0pt'> </span><span
lang=EN-US>I saw salaboy</span><span style='font-family:宋体'>’</span><span
lang=EN-US>s video claiming that to avoid using eval() in the rule. Do we have
any alternative way to do that from a performance consideration<o:p></o:p></span></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-US>Constraints
based on fields using == are best. Other things may result in eval-like
evaluations anyway. Most of the time, it isn't eval that causes performance
setbacks.<o:p></o:p></span></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;
margin-left:4.8pt;margin-right:0cm'>
<div>
<div>
<p style='margin-left:18.0pt'><span lang=EN-US>or I</span><span
style='font-family:宋体'>’</span><span lang=EN-US>d better collect/ prepare all
the data before I send them into the session?<o:p></o:p></span></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal><span lang=EN-US>Not clear what you mean by this, but if you
can provide attributes that lend themselves to straightforward constraints it
might be worthwhile considering some up-front processing of facts.<br>
<o:p></o:p></span></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;
margin-left:4.8pt;margin-right:0cm'>
<div>
<div>
<p style='margin-left:18.0pt'><span lang=EN-US>3.</span><span lang=EN-US
style='font-size:7.0pt'> </span><span
lang=EN-US>What</span><span style='font-family:宋体'>’</span><span lang=EN-US>s
you guys</span><span style='font-family:宋体'>’</span><span lang=EN-US> naming
convention for rule</span><span style='font-family:宋体'>’</span><span
lang=EN-US>s salience?<o:p></o:p></span></p>
</div>
</div>
</blockquote>
<div>
<p class=MsoNormal><span lang=EN-US>Not clear what you mean by that.<br>
<br>
-W<br>
<o:p></o:p></span></p>
</div>
<blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0cm 0cm 0cm 6.0pt;
margin-left:4.8pt;margin-right:0cm'>
<div>
<div>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> <o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>PS: my Drools version is 5.2.0.<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US> <o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>Best regards<o:p></o:p></span></p>
<p class=MsoNormal style='mso-margin-top-alt:auto;mso-margin-bottom-alt:auto'><span
lang=EN-US>Abe<o:p></o:p></span></p>
</div>
</div>
<p class=MsoNormal style='margin-bottom:12.0pt'><span lang=EN-US><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><o:p></o:p></span></p>
</blockquote>
</div>
<p class=MsoNormal><span lang=EN-US><o:p> </o:p></span></p>
</div>
</body>
</html>