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 API.
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 moment.
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 using
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 case.)
I'm going to investigate further to see quite how it happens that this flag setting makes such a big difference.
Michael Kay

From: Stephen Caffo []
Sent: 05 November 2008 15:56
Subject: [saxon] .net components, performance question

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 transformation.


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 instance.

Processor processor = new Processor();


// Load the source document

XdmNode input = processor.NewDocumentBuilder().Build(new Uri(@"C:\TestSaxon\PortfolioSnapshot\PortfolioSnapshots.xml"));


// Create a transformer for the stylesheet.

XsltTransformer transformer = processor.NewXsltCompiler().Compile(new Uri(@"C:\TestSaxon\PortfolioSnapshot\PortfolioSnapshot_In1.xslt")).Load();


// Set the root node of the source document to be the initial context node

transformer.InitialContextNode = input;


// Create a serializer

String outfile = @"C:\TestSaxon\Output.xml";

Serializer serializer = new Serializer();

serializer.SetOutputStream(new FileStream(outfile, FileMode.Create, FileAccess.Write));


// Transform the source XML to System.out.