xsl-list
[Top] [All Lists]

RE: How to speed up parsing ??

2003-07-31 09:10:23
Hi,
Here is a thread that you might want to see 
http://sources.redhat.com/ml/xsl-list/2001-02/msg01730.html click on 'Thread 
Index' to see all responses.
The general consensus from the Gurus seem to be that for-each is not slower 
than apply-templates, just one needs to find out when it is appropriate to use.
One post even quotes the Apache website as saying "for-each is faster because 
there is no template matching involved". I think you may need to look in other 
places to increase performance.

This may not be relevant to you but I thought I'd just post these performance 
tips, you can see if any apply to you
These are from noted author Michael Kay and other sources

1.      Avoid repeated use of "//item". This is very expensive. Use an Xpath 
expression that's as close to the exact one (that can identify the wanted 
nodes) as possible.
2.      Don't evaluate the same node-set more than once, save it in a variable.
3.      Avoid <xsl:number> if you can. For example, by using position() 
function.
4.      Use <xsl:key>, for example to solve grouping problems. There is an 
example of this in this document.
5.      Avoid complex patterns in template rules. Instead, use <xsl:choose> 
within the rule.
6.      Be careful when using the preceding[-sibling] or following[-sibling] 
axes. This often
        indicates an algorithm with n-squared performance.
7.      Don't sort the same node-set more than once. If necessary, save it as a 
result tree fragment
       and access it using the node-set() extension function.
8.      To output the text value of a simple #PCDATA element, use <xsl:value-of>
        in preference to <xsl:apply-templates>.
More...
1.      Keep the source documents small. If necessary split the document first.
2.      Keep the XSLT processor (and Java VM) loaded in memory between runs
3.      If you use the same stylesheet repeatedly, compile it first.
4.      If you use the same source document repeatedly, keep it in memory.
5.      If you perform the same transformation repeatedly, don't. Store the 
result instead.
6.      Keep the output document small. For example, if you're generating HTML, 
use CSS.
7.      Never validate the same source document more than once.
8.      Split complex transformations into several stages.

More...
·       Follow good performance engineering practice: record the time a 
stylesheet takes before and after making each change, and change it back if it 
doesn't improve 
·       Use small documents rather than large ones 
·       Don't assume that the processor makes a particular optimization 
·       Use variables for storing Xpath results, do not access same nodes again.
·       Use temporary trees (result tree fragments in XSLT 1.0) 
·       A 10% improvement is considered industry benchmark to justify a 
substantial change.

More...from the Apache Website
·       Avoid using predicates in '*' patterns 
·       Avoid using id/key-patterns 
·       Avoid union expressions where possible 
·       Sort stored node-sets once 
·       Cache input documents  

Lastly,
·       Follow Design Patterns!

Also, probably not logical at all, but I read on one forum that if this guy 
used  <xsl:apply-templates select="*"/> instead of <xsl:apply-templates/> the 
performance increased drastically. Just something to try.

Thanks,
Ashish



-----Original Message-----
From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com]On Behalf Of 
Dipesh
Khakhkhar
Sent: Wednesday, July 30, 2003 6:16 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] How to speed up parsing ??


Hi,

I would like to know how can i speed up parsing xml file.
I am having huge xml file (approx 30-50 MB). I have written xsl to get text 
out it. I am getting it properly but it is taking lotta time.

I have used "apply templates " frequently to go to the respective node. As per 
my knowledge "for-each" and "apply-templates" does the same thing and i assume 
internally they must be working alike. WILL THERE BE SPEED ENHANCEMENT IF I 
USE FOR-EACH INSTEAD OF USING APPLY_TEMPLATES.

Or if you do programatically the same thing will i be achieving speed 
enhancement ??

My current xsl is drastically slow. Pls give me some hints and suggestion to 
enhance performance of my xsl processing.

Eagerly waiting for reply.

Regards,
Dipesh 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



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