472,332 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,332 software developers and data experts.

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
Jul 20 '05 #1
6 2170

"Duane Morin" <dm****@morinfamily.com> wrote in message
news:55**************************@posting.google.c om...
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.)
One could refactor these as:

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

and

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

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?
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


Duane

Jul 20 '05 #2
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

dm****@morinfamily.com (Duane Morin) wrote in message news:<55**************************@posting.google. com>...
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

Jul 20 '05 #3

"Duane Morin" <dm****@morinfamily.com> wrote in message
news:55**************************@posting.google.c om...
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?
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:

<xsl:template match="A">
...
There was no template matching "A" before -- this is something totally
new -- most probably it will be useless.
<xsl:template match="foo">
...
This matches all "foo" nodes and not only "A/foo" nodes as before -- again
this is something quite different.
<xsl:template match="bar">

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
Jul 20 '05 #4
In article <55**************************@posting.google.com >,
Duane Morin <dm****@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
pt**@interlog.com
Jul 20 '05 #5
Duane Morin <dm****@morinfamily.com> wrote:
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">
...


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
Jul 20 '05 #6
> dm****@morinfamily.com (Duane Morin) wrote in message
news:<55**************************@posting.google. com>...
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


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-
Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dan | last post by:
I am a relatively new user on Oracle 9.2.0.1 and I am having trouble performance tuning this production database. I am running a large query that...
2
by: Dan | last post by:
I am a relatively new user on Oracle 9.2.0.1 and I am having trouble performance tuning this production database. I am running a large query that...
4
by: David Link | last post by:
Hi, Why does adding SUM and GROUP BY destroy performance? details follow. Thanks, David Link s1.sql: SELECT t.tid, t.title,...
31
by: bilbothebagginsbab5 AT freenet DOT de | last post by:
Hello, hello. So. I've read what I could find on google(groups) for this, also the faq of comp.lang.c. But still I do not understand why there...
5
by: Dmitry Martynov | last post by:
Consider I have the following construction "if(x is T) ...". How much this test cost? And I wonder how it is implemented. Can I gain in performace...
13
by: Jason Huang | last post by:
Hi, Would someone explain the following coding more detail for me? What's the ( ) for? CurrentText = (TextBox)e.Item.Cells.Controls; Thanks. ...
6
by: blue875 | last post by:
A tale of two queries: One query looks like this, and runs fine. We'll call this the "Customer1 query": SELECT Customer1 overall.*,...
10
by: lawrence k | last post by:
I work mostly in PHP, but at the web design firm where I work we are thinking of switching to Ruby on Rails. Our lead designer recently installed...
15
by: jim | last post by:
Maybe I'm missing something, but it doesn't look like Microsoft writes a lot of apps in .Net (although they certainly push it for others). What...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: CD Tom | last post by:
This only shows up in access runtime. When a user select a report from my report menu when they close the report they get a menu I've called Add-ins...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.