Difficult to tell without seeing your full code:

(a) if you have a very large number of templates of the form

<xsl:template match="task[@type='dishes']>

i.e. all matching the same element name, but with different predicates, then deciding which template to invoke will involve a serial search. By contrast, if you use <xsl:choose> with a similar list of conditions, then Saxon-EE will optimize this using a hash lookup.

(b) if you use saxon:discard-document() and then subsequently read the same document again, it will be read and parsed again. You should only use this function if you don't expect the document to be used more than once (and if you need the reclaim the memory). Using the -t option should tell you what documents are being read/parsed.

Basically, with performance issues the devil is in the detail. You therefore need to supply full information: e.g. two different ways of writing the same stylesheet, a representative source document, and timings for both versions of the code.

Michael Kay
Saxonica

On 23/06/2012 11:38, David Rudel wrote:
Hi all,
I'm wondering if I'm doing something wrong because when I use "<xsl:apply-templates>" rather than "<xsl:for-each>" I see a major performance hit (e.g. a 40 second operation becoming 70 seconds).

I'm wondering if it has something to do with the requirement to pass variables into the new template? In particular, variables that represent document nodes that are flagged with saxon:discard-document.

For example, suppose I have a template that processes a roster of employees. For each employee the template pulls up a record of the tasks the employee has done, where each task is a node:

<employee name="Bill">
<task type="laundry">
...
</task>
<task type="dishes">
...
</task>
<task type="laundry">
...
</task>
....
...
...
</employee>

To process these tasks, data from a separate document is required. This separate document is the same for each task but is specific to the employee (so it doesn't make sense for that document to be a global variable).

I may need to process several different kinds of task nodes for each employee, so I need to pass this individual record to each of several templates. There may be many, many different nodes that need processing, so the same record is being passed dozens of times to other templates:

<xsl:template match="/">
<xsl:for-each select="//employee>
<xsl:variable name="employeedata" select="saxon:discard-document(document (...))"/>
<xsl:apply-templates>
<xsl:with-params name="employeedata" select="$employeedata"/>
</xsl:apply-templates>
</xsl:for-each>
</xsl:template>

<xsl:template match="task[@type='dishes']>
<xsl:param name="employeedata"/>
...
</xsl:template>

<xsl:template match="task[@type='laundry']">
<xsl:param name="employeedata"/>
...
</xsl:template>
....
....

I would think that XSL processors would do everything possible to make this sort of operation not significantly more CPU-intensive than a completely pull-processing model where no variables need to be passed anywhere.

Is it normal to take such a performance hit using push processing? I've tried various other options, like simply passing the URI to the document rather than the entire document node or having the original variable be a normal document and passing the saxon:discard-document version of it. These approaches nearly tripled the run-time, though.

I'm assuming that tunnel variables will not help anything here because the templates I am calling do not call further templates, but perhaps my understanding of tunnel variables is incomplete.



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help