Re: [xslt] efficiency



On Thu, May 23, 2002 at 01:14:23PM +0400, Alexey Efimov wrote:
> Hello.
> >   use --profile to see in which templates the time is spent. Like any
> > programming language XSLT can be made quite slow in just a couple of 
> > unwisely programmed lines. Understanding the cost of each operations
> It's a very good topic. Daniel, you know all details of libxslt realization very well, so can you tell, please, which XSLT conctructions are faster (I mean time of parsing + time of transforming)?

  Hum, most of there operations are not semantically equivalent !

> <xsl:apply-templates/>
> or
> <xsl:apply-templates select="*"/>

  first is cheapest

> <xsl:for-each select="elem">...
> or
> <xsl:apply-templates select="elem"/>

  for-each will be cheaper because the template matching lookup is not needed

> <elem>...
> or
> <xsl:element name="elem">...

  first is clearly cheaper

> <elem><xsl:attribute name="elem"><xsl:value-of select="@attr-value"/>literal</xsl:attribute> ...
> or
> <elem attr-name="{@attr-value}literal">...

  hard to tell, currently the implementation of attribute value templates is
not efficient at all ...

> <xsl:value-of select="xpath-expr"/><xsl:text>literal</xsl:text>
> or
> <xsl:value-of select="concat(xpath-expr, 'literal')"/>

  hard to tell, probably at the same level.

> <xsl:value-of select="light-xpath-expr"/>....<xsl:value-of select="light-xpath-expr"/>
> or
> <xsl:variable name="var" select="light-xpath-expr"/><xsl:value-of select="$var"/>..<xsl:value-of select="$var"/>

  creating the variable, if it's cheap to evaluate probably doesn't balance
the cost of reevaluating it. First should be cheaper

> What about ther synonymic XSLT constructions?
 
  hum ???

> I used --profile option and found that all first samples are faster than the second ones. Maybe I'm not right somewhere.

  Hum, no, it mostly matches my expectations,

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard@redhat.com  | libxml GNOME XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]