xsl-list
[Top] [All Lists]

RE: [xsl] Benefits of using xsl:key

2009-11-04 14:36:03

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 


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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