XsltCompiledTransform is slow on first Transform - Undocumented behaviour

时间:2015-10-30 23:30:59

标签: c# asp.net .net xslt

We have a relatively complex XSLT file. .NET Version is 3.5 - MVC 2 app running in IIS7.5 When we do an XsltCompiledTransform.Transform, the very first time it takes about one minute. All subsequent times it takes less than a second regardless of what the input XML looks like. The initial Transform will get a StackOverflowException if we don't put it in a new thread, so we always do this in a new thread. The XsltCompiledTransform object is a static object, so we don't recreate it every time we do a Transform. This behaviour is not documented anywhere in MSDN as far as I know. The documentation states to compile your XSLT using xsltc.exe (we did this) so that it doesn't spend a lot of time compiling the XSLT when you call the Load method as it's already compiled. Unfortunately, this didn't increase the performance when we called Load, and regardless of if we Load the XSLT text or the assembly, the first Transform takes one minute, and all subsequent transforms are lightning fast. Unfortunately, this is requiring us to do a "dummy" transform on a very simple piece of XML text at startup, so that the first user will not experience a one minute delay with this transformation. The transformations are fairly large pieces of XML, but that doesn't have any impact on Transform time. If the XML is 1,500KB (typical) or less than 1KB (as in our dummy transform which has only a single XML tag) it takes about 1 minute to do the first Transform. Has anyone experienced anything like this? Any ideas on how to resolve this as this seems like undocumented behaviour.

1 个答案:

答案 0 :(得分:0)

检查网站是否有任何流量,特别是从W3C网站获取DTD或类似文件 - 他们故意“限制”这些请求以鼓励人们维护本地副本。