Re: [xsl] improving performance in creating ids

Subject: Re: [xsl] improving performance in creating ids
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 23 Apr 2019 14:53:20 -0000
> Thanks for your quick reply. the node identity comparison helped quite a
bit, although I am still around a minute for a full book of ids. I am not sure
how xsl:number would help here, and what kind of performance win it would give
over count(). I tried something with a nested transformation, but what should
I feed it?
>     <xsl:number select="*[last()]"/>
> works (given a set of preceding nodes) but it is slightly slower than a
count() in the xquery. Maybe I should be using xsl:number differently?

Saxon attempts to optimise xsl:number for the case where you are numbering
many nodes: it will try to detect cases where the result is going to be the
same as the previous execution plus 1. In fact in recent releases it is
rewritten to use an internal accumulator. Another way you can achieve a
similar effect "by hand" is with a memo function: if the ID for a node is
computed as the ID of the previous node plus 1, and the function that does
that is a memo function, then numbering N nodes will have performance
increasing linearly with N.

Michael Kay

Current Thread