RE: [xsl] problem: recursive templates slowing xalan processor down

Subject: RE: [xsl] problem: recursive templates slowing xalan processor down
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 11 May 2004 20:04:17 +0100
> I read in another post that tail recursion performs better because 
> internally some processors convert it from recursion to looping.  Are 
> there other reasons processors fare better with tail 
> recursion as well?
> 

When the last thing that a template does is to call another template (or
itself), then instead of making the call and then unwinding the stack, it is
possible to unwind the stack and then make the call. This is actually true
whether the call is recursive or not, but the benefits come with calls that
are deeply recursive. It isn't faster (the same two operations are
performed, but in the reverse order) but it avoids consuming stack space.
Generally most XSLT processors run out of stack space at a recursion depth
of 500 or so.

Michael Kay

Current Thread