Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 20th, 2005, 07:10 AM
Duane Morin
Guest
 
Posts: n/a
Default Does 'match' cost performance?

I've inherited an XSL transform that I need to squeeze every last
millisecond out of (since it's running several hundred thousand
times). I've noticed that there are 26 match clauses in the file.
They are 13 pairs that each check the same condition, like this:

<xsl:template match="A/foo">
....
<xsl:template match="B/foo">
....
<xsl:template match="A/bar">
....
<xsl:template match="B/bar">
....

Get the idea? (The XSL is generated automatically.) So what I'm
wondering is, if I restructure the whole thing so that the A/B
conditional is checked once, outside the XSL, and thus I get rid of
half my match clauses, will I gain any noticeable performance?

Duane
  #2  
Old July 20th, 2005, 07:10 AM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: Does 'match' cost performance?


"Duane Morin" <dmorin@morinfamily.com> wrote in message
news:554f29fd.0309131732.5df1bb34@posting.google.c om...[color=blue]
> I've inherited an XSL transform that I need to squeeze every last
> millisecond out of (since it's running several hundred thousand
> times). I've noticed that there are 26 match clauses in the file.
> They are 13 pairs that each check the same condition, like this:
>
> <xsl:template match="A/foo">
> ...
> <xsl:template match="B/foo">
> ...
> <xsl:template match="A/bar">
> ...
> <xsl:template match="B/bar">
> ...
>
> Get the idea? (The XSL is generated automatically.)[/color]

One could refactor these as:

*[self::B or self::B]/foo

and

*[self::B or self::B]/bar

[color=blue]
> So what I'm
> wondering is, if I restructure the whole thing so that the A/B
> conditional is checked once, outside the XSL, and thus I get rid of
> half my match clauses, will I gain any noticeable performance?[/color]

The best way to know is to try.


This will probably not result in any noticeable difference for small
transformations, but in your case there might be difference (do not expect
anything huge, though).

On the other side, it shouldn't be very difficult in the general case to
improve code, which is generated automatically. However, this might involve
more complex re-writing and even choosing a better algorithm.



=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL

[color=blue]
>
> Duane[/color]


  #3  
Old July 20th, 2005, 07:10 AM
Duane Morin
Guest
 
Posts: n/a
Default Re: Does 'match' cost performance?

Let me rephrase my question. I assume that matches are not like if's
in the sense that they are all tested and thus the ones that fail are
costing you extra processing time. I'll assume that only the proper
matches are being executed, so that if my XML has A/foo and A/bar but
not B/foo, match="A/foo" and match="A/bar" will succeed.

So, different question -- does the length of the path matter? What if
I did this:

<xsl:template match="A">
....
<xsl:template match="foo">
...
</xsl:template>
<xsl:template match="bar">
...

Is that going to gain me anything? will match="foo" execute faster
than match="A/foo" if I know that I'm inside A?

Duane

dmorin@morinfamily.com (Duane Morin) wrote in message news:<554f29fd.0309131732.5df1bb34@posting.google. com>...[color=blue]
> I've inherited an XSL transform that I need to squeeze every last
> millisecond out of (since it's running several hundred thousand
> times). I've noticed that there are 26 match clauses in the file.
> They are 13 pairs that each check the same condition, like this:
>
> <xsl:template match="A/foo">
> ...
> <xsl:template match="B/foo">
> ...
> <xsl:template match="A/bar">
> ...
> <xsl:template match="B/bar">
> ...
>
> Get the idea? (The XSL is generated automatically.) So what I'm
> wondering is, if I restructure the whole thing so that the A/B
> conditional is checked once, outside the XSL, and thus I get rid of
> half my match clauses, will I gain any noticeable performance?
>
> Duane[/color]
  #4  
Old July 20th, 2005, 07:10 AM
Dimitre Novatchev
Guest
 
Posts: n/a
Default Re: Does 'match' cost performance?


"Duane Morin" <dmorin@morinfamily.com> wrote in message
news:554f29fd.0309140746.7dbcd7dd@posting.google.c om...[color=blue]
> Let me rephrase my question. I assume that matches are not like if's
> in the sense that they are all tested and thus the ones that fail are
> costing you extra processing time. I'll assume that only the proper
> matches are being executed, so that if my XML has A/foo and A/bar but
> not B/foo, match="A/foo" and match="A/bar" will succeed.
>
> So, different question -- does the length of the path matter? What if
> I did this:
>
> <xsl:template match="A">
> ...
> <xsl:template match="foo">
> ...
> </xsl:template>
> <xsl:template match="bar">
> ...
>
> Is that going to gain me anything? will match="foo" execute faster
> than match="A/foo" if I know that I'm inside A?[/color]

I don't know if this is going to "gain" anything, but the problem is that
the set of these three templates is not at all equivalent to the previous
templates:

[color=blue]
> <xsl:template match="A">
> ...[/color]

There was no template matching "A" before -- this is something totally
new -- most probably it will be useless.
[color=blue]
> <xsl:template match="foo">
> ...[/color]

This matches all "foo" nodes and not only "A/foo" nodes as before -- again
this is something quite different.
[color=blue]
> <xsl:template match="bar">[/color]


The same as above.



If the templates now match different sets of nodes, then most probably the
output of the transformation will change, therefore there must be concern
about the correctness of the transformation -- not about the efficiency of
an incorrect transformation.


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


  #5  
Old July 20th, 2005, 07:10 AM
Patrick TJ McPhee
Guest
 
Posts: n/a
Default Re: Does 'match' cost performance?

In article <554f29fd.0309140746.7dbcd7dd@posting.google.com >,
Duane Morin <dmorin@morinfamily.com> wrote:

[...]

% What if I did this:
%
% <xsl:template match="A">
% ...
% <xsl:template match="foo">
% ...
% </xsl:template>
% <xsl:template match="bar">
% ...

It wouldn't work. You might want to try


<xsl:template match="A">
...
<xsl:apply-templates select="foo|bar" mode="A"/>
...


<xsl:template match="foo" mode="A">
...


You should use a processor which provides profiling information to compare
your various attempts.


--

Patrick TJ McPhee
East York Canada
ptjm@interlog.com
  #6  
Old July 20th, 2005, 07:10 AM
David Andriana
Guest
 
Posts: n/a
Default Re: Does 'match' cost performance?

Duane Morin <dmorin@morinfamily.com> wrote:
[color=blue]
> They are 13 pairs that each check the same condition, like this:
>
> <xsl:template match="A/foo">
> ...
> <xsl:template match="B/foo">
> ...
> <xsl:template match="A/bar">
> ...
> <xsl:template match="B/bar">
> ...[/color]

Use:

<xsl:template match="A/foo | B/foo">
...
<xsl:template match="A/bar | B/bar">
...

Yes, this will be faster.

You may want to reduce the number of sets calculated by XSLT (i.e. the
total number of "match" clauses). No matter how complicated your XPath
expression would be, it is always calculated one time only on each node,
for the whole transformation.

That is, in your original XSLT, 26 node sets are calculated, even if not
used, and no matter how many nodes there are in your XML source. But if
you refactor, you will calculate only 13.


--
David
  #7  
Old July 20th, 2005, 07:11 AM
Scott Raymond
Guest
 
Posts: n/a
Default Re: Does 'match' cost performance?

> dmorin@morinfamily.com (Duane Morin) wrote in message
news:<554f29fd.0309131732.5df1bb34@posting.google. com>...[color=blue][color=green]
> > I've inherited an XSL transform that I need to squeeze every last
> > millisecond out of (since it's running several hundred thousand
> > times). I've noticed that there are 26 match clauses in the file.
> > They are 13 pairs that each check the same condition, like this:
> >
> > <xsl:template match="A/foo">
> > ...
> > <xsl:template match="B/foo">
> > ...
> > <xsl:template match="A/bar">
> > ...
> > <xsl:template match="B/bar">
> > ...
> >
> > Get the idea? (The XSL is generated automatically.) So what I'm
> > wondering is, if I restructure the whole thing so that the A/B
> > conditional is checked once, outside the XSL, and thus I get rid of
> > half my match clauses, will I gain any noticeable performance?
> >
> > Duane[/color][/color]

Sonic's Stylus Studio v5 has a very nice XSLT Profiler (see
http://www.sonicsoftware.com/product...udio/index.ssp
for a quick description). They have a demo version, so you might try it out
for yourself. For what it's worth, I often prefer Stylus Studio to XMLSpy.

Scott-


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles