xsl-list
[Top] [All Lists]

RE: performance with template and choose

2002-09-12 02:22:35

--- "Michael Kay" <michael dot h dot kay at ntlworld dot com> wrote:


It looks as if MSXML3 isn't clever enough to spot that the different
match patterns contain common subexpressions (e.g.

KH[(_at_)Type='401']/Key[(_at_)ProdID ='83' and translate(@StopVal, '-','')
&lt;='20050911']

and so it is evaluating this subexpression several times for each
candidate node. Your rewritten code avoids this by factoring out the
subexpression so that there is a two-stage test.

Saxon won't do this optimization either, though in 7.2 I've started
to
put the logic in place to factor out common subexpressions.
Interestingly, in Saxon 7.2 you could do this yourself with a memo
function:

<xsl:template match="MD[z:type-1(.) and @ACPID='100']/@AAvl"
priority="1001" >


<xsl:function name="z:type-1" saxon:memo-function="yes">
  <xsl:param name="N"/>
  <xsl:return select=boolean($N/parent::Key[(_at_)ProdID ='83' and
translate(@StopVal, '-','')
&lt;='20050911']/parent::KH[(_at_)Type='401'])"/>
</xsl:function>

If a memo function is called twice with the same arguments, it
remembers
the result from the first time and avoids re-evaluating the function.


Wow.. Memoisation in XSLT! That's really great.

Mike, what exactly do you mean by "called twice with the same
arguments"?

For example, if the second time a corresponding argument is a different
node having the same string value (or which is "deep equal" to the
corresponding previous argument), will this be "the same argument" ?

Is there any reason (besides performance (side-effects)) why
memoisation should not be the default behaviour?



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

__________________________________________________
Do you Yahoo!?
Yahoo! News - Today's headlines
http://news.yahoo.com

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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