<div dir="ltr">To be honest this is this kind of feature (like differed evaluation of variables) I really like in XQuery and specifically in saxon. It allows a logging module without paying any runtime penalty if a level is disabled. With the limit of not being able to change logging level at runtime but I am ok with that.<br>
<br>Rémi<br><br><div class="gmail_quote">On Fri, Oct 3, 2008 at 4:50 PM, Michael Kay <span dir="ltr"><<a href="mailto:mike@saxonica.com">mike@saxonica.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">It's now handling this case. It was actually doing the
final optimization pass, the problem was that the "compareToInteger" expression,
which is only introduced by the optimizer in a previous phase, wasn't being
recognized as a candidate for further rewrite when the second operand became
constant.</font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Optimizers only improve by trying them out on new test
cases, so it's always good to get feedback like this.</font></span></div><div class="Ih2E3d">
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Michael Kay</font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"><a href="http://www.saxonica.com/" target="_blank">http://www.saxonica.com/</a></font></span></div><br>
</div><blockquote dir="ltr" style="border-left: 2px solid rgb(0, 0, 255); padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div dir="ltr" align="left" lang="en-us">
<hr>
<font size="2" face="Tahoma"><b>From:</b> <a href="mailto:remidewitte@gmail.com" target="_blank">remidewitte@gmail.com</a>
[mailto:<a href="mailto:remidewitte@gmail.com" target="_blank">remidewitte@gmail.com</a>] <b>On Behalf Of </b>Rémi
Dewitte<br><b>Sent:</b> 03 October 2008 15:38<br><b>To:</b> Michael
Kay<br><b>Cc:</b> <a href="mailto:talk@x-query.com" target="_blank">talk@x-query.com</a><br><b>Subject:</b> Re: [xquery-talk] Re:
Optimizations<br></font><br></div><div><div></div><div class="Wj3C7c">
<div></div>
<div dir="ltr">Thanks Michael for these explanations,<br>It is very good to know
these details. And a good motivation to buy Saxon-SA.<br><br>Rémi<br><br>
<div class="gmail_quote">On Fri, Oct 3, 2008 at 4:27 PM, Michael Kay <span dir="ltr"><<a href="mailto:mike@saxonica.com" target="_blank">mike@saxonica.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">This is
a case where Saxon (even Saxon-SA) has stopped optimizing when it could have
achieved a little more. The relevant part of the final expression tree
is</font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">
<return><br>
<sequence><br>
<choose><br>
<when><br>
<compareToInteger op="ge" value="4">
<div><br>
<literal value="3"
type="xs:integer"/><br></div>
</compareToInteger><br>
</when><br>
<then><br>
<directElement name="debug"
validation="preserve"><br>
<variableReference
name="dosmthg"/><br>
</directElement><br>
</then><br>
</choose>
<div><br>
<variableReference
name="dosmthg"/><br>
</sequence><br>
</return></div></font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">and it
hasn't noticed that the <when> condition is now
constant.</font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Deciding
when to stop optimizing is the trickiest part of the exercise - if you go on
too long, optimization can take longer than any run-time savings it is
delivering. In this occasion, two more passes would have paid dividends
- one to evaluate the <when> condition, the other to reduce the
<choose> to ().</font></span></div>
<div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial">Michael
Kay</font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"><a href="http://www.saxonica.com/" target="_blank">http://www.saxonica.com/</a></font></span></div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div>
<div dir="ltr" align="left"><span><font size="2" color="#0000ff" face="Arial"></font></span> </div><br></div>
<blockquote dir="ltr" style="border-left: 2px solid rgb(0, 0, 255); padding-left: 5px; margin-left: 5px; margin-right: 0px;">
<div dir="ltr" align="left" lang="en-us">
<hr>
<font size="2" face="Tahoma">
<div><b>From:</b> <a href="mailto:talk-bounces@x-query.com" target="_blank">talk-bounces@x-query.com</a> [mailto:<a href="mailto:talk-bounces@x-query.com" target="_blank">talk-bounces@x-query.com</a>] <b>On Behalf Of </b>Rémi
Dewitte<br></div><b>Sent:</b> 03 October 2008 14:24
<div><br><b>To:</b> <a href="mailto:talk@x-query.com" target="_blank">talk@x-query.com</a><br></div><b>Subject:</b> [xquery-talk]
Re: Optimizations<br></font><br></div>
<div>
<div></div>
<div>
<div></div>
<div dir="ltr">Hi again,<br><br>In the same spirit, this is not at all
optimized.<br>Maybe I need Saxon SA ?<br><br><br>declare variable $level
as xs:integer := 3 ;<br><br>declare function local:debug($l as
xs:integer,$what){<br> if($l >=4) then<br>
<debug>{$what}</debug><br> else ()<br>};<br><br>let
$dosmthg := <oki>test
trace</oki><br><br>return<br>(local:debug($level,$dosmthg),$dosmthg)<br><br><br>Rémi<br><br>
<div class="gmail_quote">On Fri, Oct 3, 2008 at 3:17 PM, Rémi Dewitte <span dir="ltr"><<a href="mailto:remi@gide.net" target="_blank">remi@gide.net</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">Hi,<br><br>I have made a little experiment after reading
Michael (Kay) blog posts about optimizations and recent James Fuller
article.<br><br>I have a question quite specific to saxon still
interesting in general.<br><br>Why in the following example even the
function call is not skipped ?<br><br><br>XQuery is ::<br><br>declare
variable $level := 3;<br><br>declare function
local:debug($what){<br> if($level >=4)
then<br> <debug>{$what}</debug><br>
else ()<br>};<br><br>let $dosmthg := <oki>test
trace</oki><br><br>return<br>(local:debug($dosmthg),$dosmthg)<br><br>When
I run saxon with -explain we get <br><br><query><br>
<globalVariables><br> <declareVariable
name="level"><br> <literal value="3"
type="xs:integer"/><br>
</declareVariable><br> </globalVariables><br>
<declareFunction name="local:debug"
tailRecursive="false"><br> <literal
value="()"/><br> </declareFunction><br>
<body><br> <let variable="dosmthg"
as="element(oki, {<a href="http://www.w3.org/2001/XMLSchema%7Duntyped" target="_blank">http://www.w3.org/2001/XMLSchema}untyped</a>)"><br>
<be><br>
<directElement name="oki"
validation="skip"><br>
<valueOf><br>
<literal value="test trace"
type="xs:string"/><br>
</valueOf><br>
</directElement><br>
</be><br>
<return><br>
<sequence><br>
<functionCall name="local:debug"
tailCall="false"><br>
<variableReference
name="dosmthg"/><br>
</functionCall><br>
<variableReference
name="dosmthg"/><br>
</sequence><br>
</return><br> </let><br>
</body><br></query><br><br>Cheers,<br>Rémi<br></div></blockquote></div><br></div></div></div></blockquote></div></blockquote></div><br></div></div></div></blockquote></div>
</blockquote></div><br></div>