xsl-list
[Top] [All Lists]

RE: [xsl] Optimizing XSLT iteration

2007-10-07 17:32:23
I don't find it surprising that 80% of the time should be in the inner loop.
I'm not greatly optimistic, but it might be worth trying to construct the
attribute value in XPath rather than XSLT:

<path class="trace" 
      d="{locus[1]/concat('M', @ellipse_x, ' ', @ellipse_y),
remove(locus,1)/concat(' L', @ellipse_x, ' ', @ellipse_y)}"/>

But I don't see this making a dramatic difference. (Saxon isn't actually
constructing text nodes as a literal reading of the spec would imply, which
really would be inefficient)

Another thing you could try is 

concat('M', substring(string-join(locus/concat('L', string(@ellipse_x), ' ',
string(@ellipse_y)), ' '), 2)

Again, I wouldn't expect a dramatic improvement.

Do check that you're allocating enough memory to the Java VM. Saxon
shouldn't have any trouble coping with 60Mb input files provided you give it
enough memory (use -Xmx512m).

A couple of people have referred to the streaming processing option in
Saxon. That's useful when memory is your problem, but it's not going to make
things go faster if you're not memory-limited. (In fact, it might do the
opposite, which is one reason that the optimization isn't done
automatically.)

How long is it actually taking? Is the elapsed time linear with the source
document size? Before looking for improvements, we need to see whether your
expectations are actually realistic.

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

-----Original Message-----
From: Sujata Gohad [mailto:sgohad(_at_)asu(_dot_)edu] 
Sent: 07 October 2007 22:50
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Optimizing XSLT iteration

Hello folks,

I have an XML file in the format:

<document src="image.tif" >
  <page x="0" y= "0" width="1012" height="506" >
    <attribute src="h" name= "page.h" value="TODO" />
    <component  id="component1" >
      <trace id="component3.trace1">
        <attribute src="h" name= "trace.h" value="TODO" />
        <locus x="371" y= "36" ellipse_x="371.269" ellipse_y="35.5983"
ellipse_major_radius= "14.3639" ellipse_minor_radius="9.81155"
ellipse_angle="0.148638" ellipse_major_axis= "0.988974 0.148091"
ellipse_minor_axis="0.148091 -0.988974" intensity="0" thickness="2"
color= "#(TODO)" KM2="1" KM4="3" KM8= "3" />
        <locus x="371" y= "37" ellipse_x="371.428" ellipse_y="36.853"
ellipse_major_radius= "14.3171" ellipse_minor_radius="9.86581"
ellipse_angle="0.327775" ellipse_major_axis= "0.946761 0.321938"
ellipse_minor_axis="0.321938 -0.946761" intensity="0" thickness="2"
color= "#(TODO)" KM2="1" KM4="3" KM8= "3" />
        <locus x="371" y= "38" ellipse_x="371.532" ellipse_y="38.2574"
ellipse_major_radius= "18.3574" ellipse_minor_radius="15.0037"
ellipse_angle="0.508344" ellipse_major_axis= "0.873552 0.486731"
ellipse_minor_axis="0.486731 -0.873552" intensity="0" thickness="1"
color= "#(TODO)" KM2="0" KM4="1" KM8= "3" />
        <locus x="371" y= "39" ellipse_x="371.482" ellipse_y="39.5204"
ellipse_major_radius= "17.479" ellipse_minor_radius="15.5356"
ellipse_angle="0.524238" ellipse_major_axis= "0.865705 0.500554"
ellipse_minor_axis="0.500554 -0.865705" intensity="0" thickness="3"
color= "#(TODO)" KM2="0" KM4="1" KM8= "3" />
         ...
         ...
         ...
        <locus x="350" y= "43" ellipse_x="350.593" ellipse_y="43.4193"
ellipse_major_radius= "30.7193" ellipse_minor_radius="25.6399"
ellipse_angle="2.10944" ellipse_major_axis= "-0.512976 0.858403"
ellipse_minor_axis="-0.858403 -0.512976" intensity="0" thickness="5"
color= "#(TODO)" KM2="0" KM4="2" KM8= "0" />
      </trace >
    </component >
  </page >
</document >


In order to convert it to SVG format:

<?xml version=' 1.0' encoding='UTF-8'?>
<?xml-stylesheet href="hvm_to_svg.css" type="text/css"? > 
<svg height="506" width= "1012"
xmlns:xlink="http://www.w3.org/1999/xlink "
xmlns="http://www.w3.org/2000/svg ">
  <image height="506" width= "1012" xlink:href="foreground.png" />
  <path d="M371.269 35.5983 L371.428 36.853 L371.532 38.2574 L371.482
39.5204 .... L350.593 43.4193" class="trace"/ > </svg >


(where .... is replaced by more "Lx y" components)


I am using the XSLT:
....
            <xsl:for-each select="component">
                <xsl:for-each select="trace">
                    <path >
                        <xsl:attribute name="class"> 
trace</xsl:attribute >
                        <xsl:attribute name="d">
                            <xsl:for-each 
select="locus[position()=1]">
                                <xsl:text >M </xsl:text >
                                <xsl:value-of select="@ellipse_x"/ >
                                <xsl:text > </xsl:text >
                                <xsl:value-of select="@ellipse_y"/ >
                            </xsl:for-each >
                            <xsl:for-each 
select="locus[position()!=1]">
                                <xsl:text > L</xsl:text >
                                <xsl:value-of select="@ellipse_x"/ >
                                <xsl:text > </xsl:text >
                                <xsl:value-of select="@ellipse_y"/ >
                            </xsl:for-each >
                        </xsl:attribute >
                    </path >
                </xsl:for-each >
            </xsl:for-each >
....

XSLT profiler shows that 80% of the time is spent in 
enumerating the "locus" elements?


Is there a way to faster iteration of the "locus" elements?


Thanks
- Sujata

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

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