[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Performance of xsl:for-each with key() lookup

Subject: Re: Performance of xsl:for-each with key() lookup
From: "Alan Painter alan.painter@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Wed, 26 Sep 2018 21:00:47 -0000
Re:  Performance of xsl:for-each with key() lookup
10 years old and still giving great value.

On Wed, Sep 26, 2018, 22:54 Michael Kay mike@xxxxxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> The answer obviously depends on the processor.
>
> With Saxon, if a variable is only referenced once, and the reference isn't
> in a loop, then it will be inlined. So if you write
>
> >   <xsl:variable name="elems" select="key('some', $value, $doc)"
> > as="element()*"/>
> >    <xsl:for-each select="$elems">
>
> then Saxon will rewrite it as
>
> >  <xsl:for-each select="key('some', $value, $doc)">
>
> The main benefit of this rewrite is better pipelining. A variable causes
> the list of items to be stored somewhere in memory; without the variable,
> each item is processed as soon as it is found.
>
> Michael Kay
> Saxonica
>
> PS: Saxon 9.1 is about 10 years ago, so my memory of it is rather rusty.
>
>
> > On 26 Sep 2018, at 21:40, Martynas JuseviD
ius martynas@xxxxxxxxxxxxx <
> xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> >
> > Hi,
> >
> > I'm using the following pattern in multiple places in my stylesheets:
> >
> >    <xsl:for-each select="key('some', $value, $doc)">
> >
> > My question is, would iteration be optimized if I selected the nodes
> > into a variable first?
> >
> >    <xsl:variable name="elems" select="key('some', $value, $doc)"
> > as="element()*"/>
> >    <xsl:for-each select="$elems">
> >
> > I guess it should be faster if the key() function is called only once
> > instead of multiple times? But if there is an index maybe it doesn't
> > matter?
> >
> > And does the same apply to
> >
> >    <xsl:apply-templates select="key('some', $value, $doc)"/>
> >
> > as well?
> >
> > I'm using Saxon 9.1.0.8.
> >
> >
> > Martynas

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.