[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Benefits of using xsl:key


Subject: RE: [xsl] Benefits of using xsl:key
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 4 Nov 2009 19:35:36 -0000

> I have now made a new input file. I transformed the original 
> input fil to a new input file making all the id attribute 
> values unique, and also all the content unique. I then hand 
> edited the new file for 15 of the elements, making the 
> content the same for some other element.
> 
> The transformation with Saxon HE, PE and EE  without using 
> xsl:key is now much faster, 4.5s, but, as a big surprise (to 
> me), the use of xsl:key has no influence on the 
> transformation speed still being 4.5s, and also the 
> optimization option in EE has no effect!

I thought I explained why that should be expected. Your match pattern
match="x[.=preceding::x]" is intrinsically very inefficient, but by chance
it was performing OK because the distance between duplicates was always
small. You have now increased the distance between duplicates, so the match
pattern becomes more expensive, and gives quadratic performance with
document size. 
> 
> I'm a little confused. My conclusion is that xsl:key can make 
> a transformation faster in some situations. It very much 
> depends on data.
> 

Using keys will only speed things up if you use them in a place where the
performance is critical. You now have very few duplicates, so you are not
executing the body of the template very often, so speeding it up gives very
little benefit. Instead you need to speed up the match pattern, which you
can do by rewriting it to use key(): I would suggest one template match="x[.
is key('k', current())[1]]" to match the first duplicate, and another
match="x" with lower priority to match the remaining duplicates.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 


Current Thread