xsl-list
[Top] [All Lists]

Re: problem: recursive templates slowing xalan processor down

2004-05-11 10:36:21
Jeni Tennison wrote:


Finally, and this is the most important rewrite, it's much better to
write a recursive template as a tail-recursive template if you can (or
as a divide-and-conquer template if there are hundreds of recursions
involved each time the template is called). A tail-recursive template
calls itself as the very last thing that it does. You need to have an
extra parameter to keep track of the current sum, and update this
parameter on each recursion. Here's what your template looks like when
it's rewritten using the advice above and as a tail-recursive
template:


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?

Thanks,
Brian