[xquery-talk] Re: Optimizations

Michael Kay mike at saxonica.com
Fri Oct 3 16:27:01 PDT 2008

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
              <compareToInteger op="ge" value="4">
                <literal value="3" type="xs:integer"/>
              <directElement name="debug" validation="preserve">
                <variableReference name="dosmthg"/>
          <variableReference name="dosmthg"/>
and it hasn't noticed that the <when> condition is now constant.
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 ().
Michael Kay


From: talk-bounces at x-query.com [mailto:talk-bounces at x-query.com] On Behalf
Of Rémi Dewitte
Sent: 03 October 2008 14:24
To: talk at x-query.com
Subject: [xquery-talk] Re: Optimizations

Hi again,

In the same spirit, this is not at all optimized.
Maybe I need Saxon SA ?

declare variable $level as xs:integer := 3 ;

declare function local:debug($l as xs:integer,$what){
  if($l >=4) then
  else ()

let $dosmthg := <oki>test trace</oki>



On Fri, Oct 3, 2008 at 3:17 PM, Rémi Dewitte <remi at gide.net> wrote:


I have made a little experiment after reading Michael (Kay) blog posts about
optimizations and recent James Fuller article.

I have a question quite specific to saxon still interesting in general.

Why in the following example even the function call is not skipped ?

XQuery is ::

declare variable $level := 3;

declare function local:debug($what){
  if($level >=4) then
  else ()

let $dosmthg := <oki>test trace</oki>


When I run saxon with -explain we get 

    <declareVariable name="level">
      <literal value="3" type="xs:integer"/>
  <declareFunction name="local:debug" tailRecursive="false">
    <literal value="()"/>
    <let variable="dosmthg" as="element(oki,
<http://www.w3.org/2001/XMLSchema%7Duntyped> )">
        <directElement name="oki" validation="skip">
            <literal value="test trace" type="xs:string"/>
          <functionCall name="local:debug" tailCall="false">
            <variableReference name="dosmthg"/>
          <variableReference name="dosmthg"/>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://x-query.com/pipermail/talk/attachments/20081003/e3510ab1/attachment-0001.htm

More information about the talk mailing list