XslCompiledTransform Performance: Beating MSXML 4.0
在 NET Framework 2.0 中, XslCompiledTransform 实现在 System.Data.SqlXml assembly 中 (为了减小Sysmtem.Xml 的大小)。缺省安装,System.Data.SqlXml assembly 没有被 NGen'd. 所以第一次使用时需要被JIT,需要很多时间。XSLT 在 Load 的时候被首先被编译成 MSIL 代码。然后在第一次运行时(Transform),MSIL代码被 JIT 成机器代码。所以每次 Load 的时候需要一些时间。 第一次Transform也需要一些时间。后续的XSLT执行(Transform)很快,因为他们已经是机器代码了。
关于几个Engine的实现:
MSXML 3.0. The native XSLT processor implemented in MSXML 3.0 is still used by default in the Internet Explorer 6.0 and 7.0. It compiled a stylesheet to a tree of "actions", each of which knew how to "execute" itself. So it worked as a pretty simple XSLT
interpreter.
- MSXML 4.0. The XSLT processor in MSXML 4.0 was completely reworked. It implemented a number of optimization techniques and compiled a stylesheet to some sort of P-code, which resulted in significantly faster transformation speed. This processor is more conformant and reliable than its MSXML 3.0 predecessor. Further versions of MSXML—5.0 and 6.0—bore the same XSLT processor as MSXML 4.0, so there is no much sense to consider them separately.
- XslTransform. The first managed XSLT processor,
XslTransform
, was a port of MSXML 3.0 code. Unfortunately, in addition to bugs and performance issues ported from MSXML 3.0, some new ones were introduced during the porting process.XslTransform
was good enough for many applications; however it was clear that its radical improvements were impossible without radical reworking of the code like the one happened between MSXML 3.0 and 4.0. - XslCompiledTransform. The .NET Framework 2.0 presents a new managed XSLT processor,
XslCompiledTransform
, which is going to replace the obsoleteXslTransform
class.XslCompiledTransform
operates as a true compiler, translating a stylesheet into a set of dynamic MSIL methods, which use the highly-optimized XSLT runtime library. While compiled stylesheets run amazingly fast, incurred set-up costs—XSLT-to-MSIL compilation time plus JIT-compilation time—are considerably higher than for other XSLT processors, which may hinder its adoption in some applications.