This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Simple problem - complicated solution - performance


Stuart Celarier wrote:
> Dimitre raises an interesting point about using recursion for computing
> the minimum and maximum values of a set of data. Let me throw this
> question back out to the list, especially to people with XSLT
> implementation experience: 
> 
> It seems like there must be some practical limits to recursion since
> that would involve a call stack in memory. Is it reasonable to think
> about recursion that stacks up a couple of thousand or tens of thousands
> of calls deep? Taking a page fault on a call stack seems like it could
> get very expensive very quickly.

I believe tail recursion is optimized like this:

If the recursive call is the final instruction in the template, you don't need
to put anything on the stack. The call can be in an xsl:if or xsl:choose/when, 
as long as there's nothing that needs to be done after it.

In other words, say you have this general structure (in pseudocode):

   myTemplate:
     take in some parameters
     add some stuff to the result tree
     if some condition is true, call myTemplate with new parameters

As long as you don't do anything else (like add some more stuff to the result
tree at the end), then with each invocation, it is safe to forget that your
template was called by a previous invocation; you'll never need to go back to
that previous one.

   - Mike
____________________________________________________________________________
  mike j. brown                   |  xml/xslt: http://skew.org/xml/
  denver/boulder, colorado, usa   |  resume: http://skew.org/~mike/resume/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]