Project

Profile

Help

Strange Performance Issue (8.4)

Added by Anonymous about 19 years ago

Legacy ID: #3110310 Legacy Poster: chris (chris1972)

Hi, This is a little bit hard to explain but I'll give it a shot. In my stylesheet, I create a variable that holds a full blown xml tree structure (node sequences). I pass this variable as a parameter to a template. That template then does some iterations of the sequences in the variable using <xsl:for-each select="$myvar/toplevel">. Well, wondering why transformation was so slow, I narrowed it down to the for-each on that variable which was taking 3 second! It's not an extremely large structure.. maybe around 300 elements or so and I'm using a very simple, explicit path to iterate over. Well if I simply use that variable for something like... <xsl:for-each select="$myvar/toplevel"> <xsl:message>x</xsl:message> </xsl:for-each> ... Then my transformation takes 3+ seconds. If I simply remove that piece (keep in mind that the transformation has way more complex things going on all over it) then the time to transform takes less than 1/2 second. So out of curiosity, I outputted the variable contents using <xsl:copy-of>, then used the output to override the variable (the one that's passed in as a param) in my template using... <xsl:variable name="myvar"> blah blah blah </xsl:variable> .. So now the variable has the EXACT same contents as the slow performer, the only difference is the template is using one that was built statically instead of dynamically (the dynamic one is still being built, just not being used). When I do this, my transformation is fast again. I hope that made some sense. Please let me know if you have any ideas or if you have any questions about my rambling. I know it may be impossible to troubleshoot without all the source, but I'm hoping that this is a common problem that somebody has a simple answer for. Thanks!


Replies (2)

RE: Strange Performance Issue (8.4) - Added by Anonymous about 19 years ago

Legacy ID: #3110337 Legacy Poster: chris (chris1972)

Never mind. I think I figured it out. By some sort of magic, Saxon knows not to process instructions for building a variable if that variable is never used. So it turns out that the lengthy processing time is occurring in construction of that variable. So when I wasn't 'using' it, it wasn't being constructed at all, hence the better performance. Sure had me fooled.

RE: Strange Performance Issue (8.4) - Added by Anonymous about 19 years ago

Legacy ID: #3112056 Legacy Poster: Michael Kay (mhkay)

Yes: Saxon uses various techniques to avoid evaluating variables that aren't needed. If there's no reference to the variable at all, then it's discarded at compile time; if it's referenced, but say in one branch of a conditional, then it's evaluated lazily, which means evaluation doesn't kick in until the value is actually needed. Also, if the value is a sequence, then evaluation will only proceed as far as necessary: e.g. if the expression that uses the variable only needs to know its effective boolean value, then it's usually only necessary to compute the first one or two items of the sequence. Michael Kay

    (1-2/2)

    Please register to reply