<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.6001.18099" name=GENERATOR></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=155244714-03102008><FONT face=Arial
color=#0000ff size=2>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 class=155244714-03102008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=155244714-03102008><FONT face=Arial
color=#0000ff size=2>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 dir=ltr align=left><SPAN class=155244714-03102008><FONT face=Arial
color=#0000ff size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN class=155244714-03102008><FONT face=Arial
color=#0000ff size=2>Michael Kay</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=155244714-03102008><FONT face=Arial
color=#0000ff size=2><A
href="http://www.saxonica.com/">http://www.saxonica.com/</A></FONT></SPAN></DIV><BR>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: #0000ff 2px solid; MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> remidewitte@gmail.com
[mailto:remidewitte@gmail.com] <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> talk@x-query.com<BR><B>Subject:</B> Re: [xquery-talk] Re:
Optimizations<BR></FONT><BR></DIV>
<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">mike@saxonica.com</A>></SPAN> wrote:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>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 face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2>
<return><BR>
<sequence><BR>
<choose><BR>
<when><BR>
<compareToInteger op="ge" value="4">
<DIV
class=Ih2E3d><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 class=Ih2E3d><BR>
<variableReference
name="dosmthg"/><BR>
</sequence><BR>
</return></DIV></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>and it
hasn't noticed that the <when> condition is now
constant.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>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 class=Ih2E3d>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2>Michael
Kay</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff size=2><A
href="http://www.saxonica.com/"
target=_blank>http://www.saxonica.com/</A></FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV dir=ltr align=left><SPAN><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV><BR></DIV>
<BLOCKQUOTE dir=ltr
style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: rgb(0,0,255) 2px solid; MARGIN-RIGHT: 0px">
<DIV lang=en-us dir=ltr align=left>
<HR>
<FONT face=Tahoma size=2>
<DIV class=Ih2E3d><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 class=Ih2E3d><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 class=Wj3C7c>
<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="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<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></BLOCKQUOTE></BODY></HTML>