When using an XSLT transformation many times, compile it
Public-service-announcement type of thing today: if you're going to be applying an XSLT transformation multiple times, be sure to compile the transformation and then reuse it. This saves you CPU time to re-compile them, memory used during the recompilation, memory fragmentation from the increased memory churn, and presumably you'll get more cache hits from reusing the same pages used for the compiled form. All goodness.
Here is how to do this using MSXML: https://msdn.microsoft.com/en-us/library/ms763679(VS.85).aspx.
In .NET it is simpler, as using the XslCompiledTransform class naturally takes you down the path of having a precompiled form of the transformation. Just make sure to cache the object instead of recreating it from the same XML source every time.
Enjoy!
Comments
- Anonymous
February 11, 2010
Agreed. This can also be used in a multi-threaded setup, potentially giving even better performance.