This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Performance


> What is the best way to improve performance?

Some tips:
- do fewer transformations (don't do the same transformation twice; cache
the results)
- compile stylesheets and reuse them
- reduce startup costs by not reloading the Java VM etc
- supply the source document as a SAX stream or byte stream, not as a DOM
- avoid serializing a document and then reparsing it
- if you transform the same source document more than once, don't reparse it
each time
- avoid doing XSLT transformations on very large documents if you can;
consider splitting the document into smaller pieces. 10Mb is about the
limit, depending of course on how much memory you have.

- look at any XPath expressions that use axes other than child, parent, or
attribute. How many nodes will they access? How often will they be executed?
Can you use variables or keys to reduce the number of nodes visited? Can you
replace a complex single-phase transformation with a simpler two-phase
transformation?
- look at any XPath expressions that use the "=" operator to compare
node-sets (especially with non-singular node-sets on both sides). How many
comparisons will be needed? Can the number be reduced using keys or
variables?
- look carefully at any instructions that use xsl:number or count(). They
may need to access many nodes. Can you achieve the same effect using
position()?
- try to replace expressions that use "//" with a more explicit path.
- look in particular at the template rules that will be executed most
frequently. How often will the rule be executed, and how many nodes in the
source tree will it access?
- look at any template rules with complex match patterns. Combining several
template rules and using xsl:choose might help.

- set up a repeatable benchmark for measuring performance, that is
representative of your real workload. Measure results, record them, make
changes one at a time, measure the effect of each change, record the
results, reverse the change if it gives no benefit.

- use tracing facilities (e.g. Saxon's -T) to understand which instructions
in your stylesheet are being executed most often. If necessary, do detailed
profiling of where the time is being spent (but that's usually difficult).

Obviously the details are processor-dependent. In particular, different
processors do different optimisations.

Miek Kay
-


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]