fastest in-memory cache for XslCompiledTransform

2019-05-27 10:15发布

问题:

I have a set of xslt stylesheet files. I need to produce the fastest performance of XslConpiledTransform, so i want to make in-memory representation of these stylesheets.

I can load them to in-memory collection as IXpathNavigable on application start, and then load each IXPAthNavigable into singleton XslCompiledTransform on each request. But this works only for styleshhets without xsl:import or xsl:include. (Xsl:import is only for files).

also i can load into cache many instances of XSLCompiledTransform for each template. Is it reasonable?

Are there other ways? What is the best? what are another tips for improving performance MS Xslt processor?

回答1:

After the successful execution of Load() on an instance of XslCompiledTransform, this instance can be cached in order to achieve better performance.

Do remember that Load() is a very expensive operation.



回答2:

Instead of compiling and caching XSL transforms at run time you can use the MS SDK tool xsltc.exe (XSL compiler) to generate assemblies.

At runtime your application will then either load these assemblies dynamically (or you can just add static references to your application) and call the overloaded XslCompiledTransform.Load( System.Type type) method to load the type that you compiled into the XSL assembly.

This is the absolute fastest way since you dont incur the compile penalty of runtime - only at build/compile time.