[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Performance problem


Subject: RE: [xsl] Performance problem
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 15 Feb 2005 12:01:38 -0000

There doesn't seem to be anything grossly inefficient in this stylesheet so
the first thing to do is to establish some parameters:

(a) how large is the source file?
(b) how long is it taking?
(c) what is the performance requirement?
(d) what XSLT processor are you using, and in what environment?
(e) how does the performance scale as the source file size increases: is it
linear?

It's easy to come up with tweaks that might make it 10% faster, but in my
experience if people have a performance problem then 10% isn't going to help
much.

One observation that might be relevant: I discovered in the past that
format-number(), if implemented in Java, runs very slowly with some Java
VMs. Problems like this reveal themselves if you run the stylesheet with
more than one processor and get very different results.

Michael Kay
http://www.saxonica.com/ 


> -----Original Message-----
> From: ficfic m [mailto:ficfic@xxxxxxxxxxx] 
> Sent: 15 February 2005 11:32
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Performance problem
> 
> 
> Hi all,
> 
> I've tried to find tips on how to improve the performance of 
> my XSL file and 
> so far did not find something meaningful.
> The most time-consuming part in my xml is a big-list of items
> 
> <data>
> 	<item name="abc" timestamp="2004-10-11T15:49:31">
> 		<bytes> 1062207488</bytes>
> 	</item>
> <item name="efd" timestamp="2004-10-13T15:44:31">
> 		<bytes>23457</bytes>
> 	</item>
> ....
> </data>
> 
> I process the timestamp field as follow:
> INPUT -> 2004-10-11T15:49:31   OUTPUT -> 2004-Oct-11 15:49:31
> 
> I process the bytes field as follow:
> INPUT -> 1048576                    OUTPUT -> 1,013MB
> 
> And display it all in a table.
> 
> My xsl file:
> <xsl:template match="data">
> <table border="1" cellspacing="0" cellpadding="3">
> 	<tr>
> 		<th>Name</th>
> 		<th>Bytes</th>
> 		<th>Time Stamp</th>
> 	</tr>
> 	<xsl:for-each select="item">
> 	<tr>
> 	<td nowrap="1">
> 		<xsl:value-of select="@name"/>
> 	</td>
> 	<td>
> 		<xsl:choose>
> 		<xsl:when test="bytes">
> 			<xsl:call-template name="format-bytes">
> 				<xsl:with-param 
> name="bytes_cnt" select="bytes"/>
> 			</xsl:call-template>
> 		</xsl:when>
> 		<xsl:otherwise>
> 			<xsl:text>&#160;</xsl:text>
> 		</xsl:otherwise>
> 		</xsl:choose>
> 	</td>
> 	<td nowrap="1">
> 		<xsl:call-template name="format-date">
> 			<xsl:with-param name="date-time" 
> select="@timestamp"/>
> 		</xsl:call-template>
> 	</td>
> 	</tr>
> 	</xsl:for-each>
> 	</table>
> </xsl:template>
> 
> <!-- prints-out bytes count -->
> <xsl:variable name="Mega" select="1024 * 1024"/>
> <xsl:variable name="Giga" select="1024 * $Mega"/>
> 
> <xsl:template name="format-bytes">
> <xsl:param name="cnt_bytes" select="."/>
> <xsl:choose>
> 	<xsl:when test="$ cnt_bytes &lt; 1024"><xsl:value-of 
> select="format-number($cnt_bytes, '#,##0')"/>Bytes</xsl:when>
> 	<xsl:when test="$ cnt_bytes &lt; $Mega"><xsl:value-of 
> select="format-number($cnt_bytes div 1024, '#,###.##')"/>KB</xsl:when>
> 	<xsl:when test="$ cnt_bytes &lt; $Giga"><xsl:value-of 
> select="format-number($cnt_bytes div $Mega, 
> '#,###.##')"/>MB</xsl:when>
> 	<xsl:when test="$ cnt_bytes"><xsl:value-of 
> select="format-number($cnt_bytes 
> div $Giga, '#,###.##')"/>GB</xsl:when>
> 	<xsl:otherwise><xsl:text>&#160;</xsl:text></xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> 
> <!-- prints-out timestamp in format : dd-mon-yy H:M:S -->
> 
> <xsl:template name="format-date">
> <xsl:param name="date-time" select="."/>
> <xsl:choose>
> <xsl:when test="$date-time">
> 	<xsl:value-of select="substring($date-time, 9 ,2)"/>
> 	<xsl:text>-</xsl:text>
> 	<xsl:variable name="month" 
> select="substring($date-time, 6 ,2)"/>
> 	<xsl:choose>
> 		<xsl:when test="$month = 1">Jan</xsl:when>
> 		<xsl:when test="$month = 2">Feb</xsl:when>
> 		<xsl:when test="$month = 3">Mar</xsl:when>
> 		<xsl:when test="$month = 4">Apr</xsl:when>
> 		<xsl:when test="$month = 5">May</xsl:when>
> 		<xsl:when test="$month = 6">Jun</xsl:when>
> 		<xsl:when test="$month = 7">Jul</xsl:when>
> 		<xsl:when test="$month = 8">Aug</xsl:when>
> 		<xsl:when test="$month = 9">Sen</xsl:when>
> 		<xsl:when test="$month = 10">Oct</xsl:when>
> 		<xsl:when test="$month = 11">Nov</xsl:when>
> 		<xsl:when test="$month = 12">Dec</xsl:when>
> 	</xsl:choose>
> 	<xsl:text>-</xsl:text>
> 	<xsl:value-of select="substring($date-time, 3 ,2)"/>
> 	<xsl:text> </xsl:text>
> 	<xsl:value-of select="substring($date-time, 12 ,8)"/>
> </xsl:when>
> <xsl:otherwise>
> 	<xsl:text>&#160;</xsl:text>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
> 
> 1. How can I improve this code?
> 2. Should I use the <for-each> or <xsl:template match="item"> ?
> 3. In 1/3 of the times the "bytes" element doesn't appears in 
> the xml file, 
> that is why I put a check before calling the "format-bytes" 
> template, do you 
> think is it best to always call the template and then check 
> inside of the 
> template if it exists ?
> 4. Do you think I should use xsl:template or xsl:function to 
> format my 
> timestamp/bytes ?
> 
> Best Regards,
> ficfic
> 
> _________________________________________________________________
> Express yourself instantly with MSN Messenger! Download today 
> it's FREE! 
> http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Current Thread
Keywords