I wanted to migrate my XslCompiledTransform to Saxon 9.7.0.6 HE because of XPath 2.0/XSLT 2.0, but it is way slower than .NET.
I tested each version with a default copy ident XSLT and 15.000 xml files:
Saxon with Parallel.ForEach: 00:05:02.9013605
XslCompiledTransform with Parallel.ForEach: 00:00:15.6724146
Saxon with foreach: 00:10:09.7763861
XslCompiledTransform with foreach: 00:03:00.3483324
I hope I do something wrong, XslCompiledTransform:
XslCompiledTransform xslt = new XslCompiledTransform();
xslt.Load(xsl);
XmlWriterSettings writerSettings = xslt.OutputSettings.Clone();
XmlReaderSettings readerSettings = new XmlReaderSettings();
readerSettings.DtdProcessing = DtdProcessing.Ignore;
readerSettings.XmlResolver = null;
Parallel.ForEach(files, file =>
{
string target = Path.Combine(output, Path.GetFileName(file));
using (XmlReader xr = XmlReader.Create(file, readerSettings))
using (XmlWriter xw = XmlWriter.Create(target, writerSettings))
xslt.Transform(xr, xw);
});
The Saxon Version:
Processor processor = new Processor();
DocumentBuilder docBuilder = processor.NewDocumentBuilder();
docBuilder.DtdValidation = false;
docBuilder.SchemaValidationMode = SchemaValidationMode.None;
docBuilder.WhitespacePolicy = WhitespacePolicy.PreserveAll;
XsltCompiler compiler = processor.NewXsltCompiler();
XsltExecutable executable = compiler.Compile(new Uri(xsl));
Parallel.ForEach(files, file =>
{
string target = Path.Combine(output, Path.GetFileName(file));
XsltTransformer transformer = executable.Load();
XdmNode input = docBuilder.Build(new Uri(file));
transformer.InitialContextNode = input;
Serializer serializer = new Serializer();
serializer.SetOutputFile(target);
transformer.Run(serializer);
});
Update
I did another test without Visual Studio debugging and it got a lot better:
Saxon: 00:00:41.5990128
XslCompiledTransform: 00:00:19.0441044
So the main slow down was the debugger itself, but only for Saxon. Now it only takes twice the time of the .NET version, it is not super great, but I think I can go with that.
Is there anything I can do to make Saxon faster? Maybe play with the code or using EE instead of HE?
Here are some detailed benchmark information, the main performance problem is the DocumentBuilder.Build method. But even the transform itself is more than twice as slow as the .NET version:
Saxon:
.NET:



