Re: RE: [xsl] xslt performance issue position() function used in predicate very slow

Subject: Re: RE: [xsl] xslt performance issue position() function used in predicate very slow
From: krzysztof@xxxxxxxxxxxx
Date: Fri, 25 Aug 2006 16:16:54 +0200
You are right  $p is a string if I use number($p) it also works anyhow
that type conversion is not  main reason for my perf problem

I'm using latest 1.1.17 libxslt , I also tried Xalan but it is two times slower
(not to mention that there is some bug in supporting xsl:variable)

I tried your suggestion with xsl:variable but there is virtually no difference :-(

Maybe this is stupid question but how you can declare variable to be integer type
Is below change the answer ??? ;-)

the value for  $p was assigned this way  
<xsl:variable name="p" select="./@p"/>
when I changed it to 
<xsl:variable name="p" select="number(./@p)"/>
then xslt runs two times faster i.e. from 20sec to 10sec great but still
it's way to slow any suggestions ???

BTW such a small change and such  improvement it's really amazing :-)))

thanks
Chris
On Fri, 25 Aug 2006 13:08:21 +0100, "Michael Kay" wrote:

> Firstly, the fact that ./v[$p] doesn't work, but ./v[$p + 0] does work,
> means that the value of $p is not a number. Perhaps it is a string, or
> perhaps it is a result tree fragment. Either way, you would probably get an
> immediate performance improvement by changing it to be a number, to avoid
> the conversion costs each time the value is used.
> 
> Incidentally, the expression "./v" is exactly the same as "v". If your
> processor is particularly stupid, the more complex expression might take
> longer to evaluate.
> 
> It's of course entirely dependent on your XSLT processor whether the
> expression v[$p] takes constant time, or time proportional to $p. It looks
> as if in your case, it's taking time proportional to $p. That would be the
> case if you were using Saxon. In Saxon you could get round this by using a
> variable:
> 
> <xsl:variable name="vseq" select="v"/>
> <xsl:for-each....
>   <xsl:value-of  select="$vseq[$p]"
> 
> But that wouldn't necessarily help on a different processor. Note also that
> this only works if $p is known at compile time to be a number - so you need
> to fix that problem first.
> 
> Michael Kay
> http://www.saxonica.com/
>  
> 
> > -----Original Message-----
> > From: krzysztof@xxxxxxxxxxxx [mailto:krzysztof@xxxxxxxxxxxx] 
> > Sent: 25 August 2006 12:20
> > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> > Subject: [xsl] xslt performance issue position() function 
> > used in predicate very slow
> > 
> > Hi,
> > 
> > I'm processing xml files that have 150kB size they are 
> > composed from xml blocks that contain 350 elements with int 
> > values here is example
> > 
> > &lt; obj name="obj1">
> >  &lt;v>1&lt;/v>
> >  &lt;v>2&lt;/v>
> >  &lt;v>3&lt;/v>
> >  ....
> >  &lt;v>350&lt;/v>
> > &lt;/obj>
> > 
> > obj blocks are  repeated many times
> > in general my xslt selects some  set of &lt;v> rows and saves 
> > in csv format e.g. select  1,2,3,4,15,28,71,17,19 and save to 
> > csv in my xslt I'm using below expression to select v rows
> > 
> > &lt;xsl:value-of select="./v[position()=$p]"/>
> > 
> > ( in for-each loop I assign value to $p variable)
> > 
> > on P4 2.8 Ghz 512MB ram it takes 20 seconds! to parse 150KB file !!!
> > if I comment out  this line it takes 1 second so definitely 
> > it's issue with
> > position()
> > and selecting this v values.
> > 
> > BTW abbreviated version doesn't wok  i.e. select="./v[$p]" 
> > but select="./v[$p+0]" works is this some bug ???
> > 
> > Thanks for any tips how to improve performance 
> > 
> > Chris

Current Thread