Re: [xsl] Performance differences between xsl:for-each and xsl:template matches

Subject: Re: [xsl] Performance differences between xsl:for-each and xsl:template matches
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 16 Aug 2022 19:24:43 -0000
With performance, the devil is always in the detail. Don't make coding changes
with the aim of improving performance unless you know where the
problems/bottlenecks are. The way to make things faster is to focus your
efforts on measurement and analysis, not on experimenting with different ways
of writing your code. Before you do anything else, work out whether this
transformation is critical in your overall workload, and if so, whether its
timing is dominated by source document parsing and tree building, by
stylesheet compilation, or by serialization costs, rather than by the actual
transformation itself.

What kind of performance improvement do you need to achieve? 10% faster, or 10
times faster? What resources are you prepared to invest in order to achieve
it?

Michael Kay
Saxonica

> On 16 Aug 2022, at 18:56, Liam R. E. Quin liam@xxxxxxxxxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Tue, 2022-08-16 at 17:12 +0000, Edward Porter edward.porter@xxxxxxx
> wrote:
>> I inherited an older stylesheet that makes extensive use of <xsl:for-
>> each> matching elements (e.g., select="//chapter[@eid]") in the root
>> template to then call templates. Using Saxon, would there be any
>> performance improvements if I refactored to use match templates and
>> <xsl:apply-templates> as would generally be the best practice in this
>> case?
>
> The first thing i'd look at is whether you can replace a whole bunch of
> for-each mappings with a single apply-templates instruction. The // in
> your example walks the entire document tree (in principle) making a
> list of all chapter elements with an eid attribute. If you can replace
> lots of similar things with a *single* treewalk using apply-templates
> it'll likely go faster. There's rarely a single answer for performance
> questions.
>
> liam
>
>
> --
> Liam Quin - paligo.net, delightfulcomputing.com
> Cancer gofundme https://www.gofundme.com/f/5u9v7-every-little-helps
> Vintage pictures & texts https://www.fromoldbooks.org/

Current Thread