开发者

XSLT transformation Performance in .net

开发者 https://www.devze.com 2023-03-06 05:55 出处:网络
Our programs are frequently contacting other systems to fetch the data andthere are frequent data copy from the contracts exposed by other systems to the required applications contract pattern.So we h

Our programs are frequently contacting other systems to fetch the data and there are frequent data copy from the contracts exposed by other systems to the required applications contract pattern. So we have created a utility that accepts an XSLT file and this will do the transformation to the required object. So whoever developing a new module has to just provide the XSLT file. Now i feel that there is a performance Hit especially when the incoming object is slight bigger and when it get serialized for transformations it will be even more bigger and occupy much memory. So is there a way to optimize this further ?. I am using XSLT compiled transform Is this better than the normal trans开发者_开发知识库form ?. or is there any other way to improve performance ?. Kindly Advice


Since .NET 3.5 there is xsltc.exe http://msdn.microsoft.com/en-us/library/bb399405.aspx as part of the .NET framework SDK, it allows you to precompile an XSLT stylesheet to reduce the work XslCompiledTransform has to do usually when you load an XSLT stylesheet as an XML document. I don't know whether that is an option for you as you seem to get various XSLT stylesheets as the input. As for memory consumption, XSLT (1.0 as well as 2.0) works on an in-memory tree model of the complete XML input documents so there is not much you can do to keep memory usage low with big input documents, other than letting the XSLT processor choose its own favourite tree implementation. In the case of XslCompiledTransform it is XPathDocument in System.Xml.XPath.

Other options you could explore are moving to third party XSLT 2.0 (XQSharp, Saxon 9) or even 3.0 implementations like Saxon 9.3, as Saxon 9.3 has a streaming mode http://www.saxonica.com/documentation/sourcedocs/streaming.xml that can help to keep memory usage low when processing large or very large input documents.


Now i feel that there is a performance Hit especially when the incoming object is slight bigger and when it get serialized for transformations it will be even more bigger and occupy much memory. So is there a way to optimize this further ?.

This isn't a specific question as any performance-related question should be.

One should perform measurements to identify any existing bottlenecks and only then consider optimizing these.

Or, to quote Donald Knuth:

"Premature optimization is the root of all evil"

An XmlDocument or an XPathDocument object does not need at all to be serialized in order to be able to perform XSLT transformation. There are a number of overloads of the Transform() method of XslCompiledTransform that accept an IXPathNavigable argument.

I am using XSLT compiled transform Is this better than the normal transform ?

There is nothing called "normal transform" in .NET. You are probably referring to the Transform class. If so, the answer is that this class was used in .NET1.1 and has been made obsolete since five years ago. The XslCompiledTransform class is the one that should be used for XSLT 1.0 transformations. It is one of the fastest XSLT 1.0 processors from any vendor that exist.

0

精彩评论

暂无评论...
验证码 换一张
取 消