[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: How smart are the XSLT processors? Are there any X

Subject: RE: How smart are the XSLT processors? Are there any XSLT processors that convert tree-recursive functions into efficient iterative procedures?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 28 Apr 2010 09:50:45 +0100
RE:  How smart are the XSLT processors? Are there any X
> Are there any XSLT processors that convert tree recursive 
> functions into more efficient iterative procedures?
> 
> /Roger
> 
> -------------------------------------------------
>      Version #1: Tree Recursion
> -------------------------------------------------
>     <xsl:function name="ex:fibonacci">
>       <xsl:param name="n" />
> 
>       <xsl:choose>
>           <xsl:when test="$n eq 0">
>               <xsl:value-of select="0" />
>           </xsl:when>
>           <xsl:when test="$n eq 1">
>               <xsl:value-of select="1" />
>           </xsl:when>
>           <xsl:otherwise>
>               <xsl:value-of select="ex:fibonacci($n - 1) + ex:fibonacci($n
- 2)" />
>           </xsl:otherwise>
>       </xsl:choose>
> 
>     </xsl:function>
>

I think it's unlikely that an XSLT implementor would optimize this to avoid
the exponential nature of the algorithm. The reason is that it's difficult
to find optimizations that would do this that are sufficiently general to
optimize a significant number of real user-written programs - there's no
point in spending effort on optimizations that only help with ivory-tower
examples. 

The most realistic optimization that one might attempt for this function is
to turn it automatically into a memo-function. That involves a space-time
tradeoff; automating a choice that requires a space-time tradeoff requires a
cost-based optimizer that understands the costs of space and time and is
able to estimate how much of either will be used. It's easy to look at this
particular function and produce an argument as to why it should be
implemented as a memo-function. It's not at all easy to generalize that
reasoning so it can produce a good answer for any function.

Optimization techniques are advancing all the time (just look at the
advances with just-in-time approaches that benefit from learning about the
behaviour of the code at run-time). But for this example, it's not there
yet.

I'd be interested how the performance of this compares with your other
implementation if you add saxon:memo-function="yes".

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.