xsl-list
[Top] [All Lists]

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

2018-09-26 17:18:31
On Wed, 26 Sep 2018 at 23:07, Michael Kay mike(_at_)saxonica(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Shame that the download link no longer works. And I'm not sure I've got an 
archive version either, I think I was assuming at the time that putting 
things on the web gave them permanence.


the doc (but not the software zip file) I think is in the internet
archive, for example this 1999 snapshot


https://web.archive.org/web/19990220013518/http://home.iclweb.com/icl2/mhkay/saxon.html



I do remember that the early attempts at streaming gave me no end of trouble, 
and were soon abandoned. The analysis of what was streamable and what wasn't 
was hopelessly fragile.

Michael Kay
Saxonica

On 26 Sep 2018, at 22:50, Wendell Piez wapiez(_at_)wendellpiez(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hey Alan, check out version 4, I'm sure Mike Kay doesn't remember the
details of that one either --

https://markmail.org/message/bapqkmmd7bz2fxce

Probably wasn't providing late variable binding.

Still giving great value! So far we have come!

Cheers, Wendell

On Wed, Sep 26, 2018 at 5:01 PM Alan Painter 
alan(_dot_)painter(_at_)gmail(_dot_)com
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

10 years old and still giving great value.

On Wed, Sep 26, 2018, 22:54 Michael Kay mike(_at_)saxonica(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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 Jusevičius 
martynas(_at_)atomgraph(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 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


XSL-List info and archive
EasyUnsubscribe (by email)



--
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^


--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>