My initial conclusion on this is that it's caused by the
fact that when running from the command line, the "allNodesUntyped" flag is set
on the Configuration, whereas this is not the case when running using the
This flag is known to cause a performance difference, but I
have never seen it cause such an enormous performance difference (I would expect
something more like 10%), and I haven't yet determined why this should happen
here. It's probably because the knowledge that all nodes are untyped enables
some powerful optimization to take place; but that's conjecture at the
Since you're using Saxon-B, Saxon should know in advance
that all nodes are untyped, and should be able to set this flag automatically,
so I'll be looking into that as part of the solution.
You can set this flag from the .NET API
but you will need to add a couple of references to your
build (saxon9.dll and the OpenJDK dll).
Given the fact that type information theoretically helps
performance, it might seem odd that Saxon performs faster if it knows that all
nodes will be untyped. The solution to this paradox is that "untyped" is really
just another type, and Saxon can take advantage of knowing that nodes are
untyped just as it can use the fact that they are typed. The worst of all
possible worlds is not knowing in advance. In particular, Saxon can often
generate better code if it knows that elements and attributes will not be
list-valued (which in Saxon-B, of course, will always be the
I'm going to investigate further to see quite how it
happens that this flag setting makes such a big difference.
I have a fairly large transformation that runs very quickly
(about 4 sec) when called from the command line with transform.exe. In
fact, it did a lot better than Altova’s engine with the same
But when I try the same transformation with the .net Saxon
components (code below), it runs for over 70 sec. Am I doing something
wrong? Do I need to buy the “SA” version to get the faster .net
components or something?
// Create a
Processor processor = new Processor();
// Load the
XdmNode input =
// Create a
transformer for the stylesheet.
XsltTransformer transformer =
// Set the
root node of the source document to be the initial context
// Create a
String outfile = @"C:\TestSaxon\Output.xml";
Serializer serializer = new Serializer();
serializer.SetOutputStream(new FileStream(outfile, FileMode.Create, FileAccess.Write));
the source XML to System.out.