Add one useless line will make xslt run faster. Who can tell me why?
The following xslt run very slow.It will take about 7 minutes.
<xsl:variable name="tags" select="$currentPage/descendant-or-self::*[@isDoc and isTag='1']/@id"/> <xsl:variable name="nodes" select="$root//*[@isDoc and umbraco.library:Split(tags,',')//value=$tags]"/>
But when I add one useless line, It will take no more than 1 minute.
<xsl:variable name="tags" select="$currentPage/descendant-or-self::*[@isDoc and isTag='1']/@id"/> <xsl:value-of select="substring($tags,1,0)"/> <xsl:variable name="nodes" select="$root//*[@isDoc and umbraco.library:Split(tags,',')//value=$tags]"/>
I can't tell you why, because it's almost certainly a quirk in the XSLT Processor that makes this happen.
Does those two lines by themselves take 7 minutes to execute?
You're not running this inside a for-each or accidentally using apply-templates on many more nodes than you think you are? (Just trying to find out where the bottleneck is).
Anyway — I recently suggested using keys() to solve another performance related problem, which as it turned out, did exactly the trick - you may be able to use that to speed up your queries as well.
With XPath, there's usually more than one way to do it, and some may be more efficient than others. Whenever possible, you should avoid the // (or descendant-or-self::) axis - starting from the topmost node that could possibly be selected can help a lot (if it's possible).
Add one useless line will make xslt run faster. Who can tell me why?
The following xslt run very slow.It will take about 7 minutes.
<xsl:variable name="tags" select="$currentPage/descendant-or-self::*[@isDoc and isTag='1']/@id"/>
<xsl:variable name="nodes" select="$root//*[@isDoc and umbraco.library:Split(tags,',')//value=$tags]"/>
<xsl:variable name="tags" select="$currentPage/descendant-or-self::*[@isDoc and isTag='1']/@id"/>
<xsl:value-of select="substring($tags,1,0)"/>
<xsl:variable name="nodes" select="$root//*[@isDoc and umbraco.library:Split(tags,',')//value=$tags]"/>
Who can tell my why?
Hi sun,
I can't tell you why, because it's almost certainly a quirk in the XSLT Processor that makes this happen.
Does those two lines by themselves take 7 minutes to execute?
You're not running this inside a for-each or accidentally using apply-templates on many more nodes than you think you are? (Just trying to find out where the bottleneck is).
Anyway — I recently suggested using keys() to solve another performance related problem, which as it turned out, did exactly the trick - you may be able to use that to speed up your queries as well.
With XPath, there's usually more than one way to do it, and some may be more efficient than others. Whenever possible, you should avoid the // (or descendant-or-self::) axis - starting from the topmost node that could possibly be selected can help a lot (if it's possible).
/Chriztian
But How to use key()
is working on a reply...